PHPackages                             monadial/phpunit-docrunner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. monadial/phpunit-docrunner

ActiveLibrary[Testing &amp; Quality](/categories/testing)

monadial/phpunit-docrunner
==========================

Rust-style doc tests for PHP - run code examples in docblocks as PHPUnit tests

01[1 PRs](https://github.com/monadial/phpunit-docrunner/pulls)PHPCI passing

Since Feb 15Pushed 2mo agoCompare

[ Source](https://github.com/monadial/phpunit-docrunner)[ Packagist](https://packagist.org/packages/monadial/phpunit-docrunner)[ RSS](/packages/monadial-phpunit-docrunner/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

PHPUnit DocRunner
=================

[](#phpunit-docrunner)

Rust-style doc tests for PHP. Write executable code examples in your docblocks or as PHP attributes, and run them as PHPUnit tests.

Requirements
------------

[](#requirements)

- PHP 8.4+
- PHPUnit 12.0+

Installation
------------

[](#installation)

```
composer require monadial/phpunit-docrunner
```

Usage
-----

[](#usage)

Write PHP code blocks in docblocks or use `#[DocTest]` attributes:

```
class Calculator
{
    /**
     * ```php
     * $result = Calculator::add(2, 3);
     * self::assertEquals(5, $result);
     * ```
     */
    public static function add(int $a, int $b): int
    {
        return $a + $b;
    }
}
```

```
use Monadial\DocRunner\Attribute\DocTest;

class Calculator
{
    #[DocTest(

        .doctest-cache/generated

```

The extension generates tests during bootstrap and warns if the generated directory isn't in your test suite config.

Configuration
-------------

[](#configuration)

Optional `doctest.xml` for project defaults:

```

        src/

        *Test.php

    .doctest-cache/
    vendor/autoload.php

```

How It Works
------------

[](#how-it-works)

Source files are parsed via AST (nikic/php-parser) — no files are `require`-ed. Code blocks are extracted from docblocks and `#[DocTest]` attributes, then generated as PHPUnit `TestCase` classes. Each source file produces one test class; each code block becomes one test method. Namespace and imports carry over from the source file.

Generated tests are cached by content hash. Unchanged files are skipped on subsequent runs.

License
-------

[](#license)

MIT

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance56

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9887dfedce25e561429934003d89e119611ad26f2cfa4fc65ee1f7914a6d2ca3?d=identicon)[tmihalicka](/maintainers/tmihalicka)

---

Top Contributors

[![tmihalicka](https://avatars.githubusercontent.com/u/1620790?v=4)](https://github.com/tmihalicka "tmihalicka (24 commits)")

### Embed Badge

![Health badge](/badges/monadial-phpunit-docrunner/health.svg)

```
[![Health](https://phpackages.com/badges/monadial-phpunit-docrunner/health.svg)](https://phpackages.com/packages/monadial-phpunit-docrunner)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
