PHPackages                             draw/tester - 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. draw/tester

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

draw/tester
===========

Library base on phpunit to test your data with a fluent interface.

0.39.2(2mo ago)057.8k↑113.2%19MITPHP

Since Apr 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mpoiriert/tester)[ Packagist](https://packagist.org/packages/draw/tester)[ RSS](/packages/draw-tester/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (20)Versions (266)Used By (19)

Tester
======

[](#tester)

This package provide a set of tools to help you test your application.

Data Tester
-----------

[](#data-tester)

This library is a wrapper around **PHPUnit Assert** class to be able to use a fluent interface on the data you want to test.

Here is a quick example of how to use it in a **PHPUnit TestCase**:

```
namespace Your\Project\Name;

use PHPUnit\Framework\TestCase;
use Draw\Component\Tester\DataTester;

class SimpleTest extends TestCase
{
    public function test()
    {
        $data = [
          'key1' => 'value1',
          'key2' => (object)['toto' => 'value']
        ];

        $dateTester = new DataTester($data);
        $dateTester
            ->assertIsArray('array')
            ->assertCount(2)
            ->path('[key1]')->assertSame('value1');

        $dateTester->path('[key2].toto')->assertSame('value');
    }
}
```

PHPUnit Extension
-----------------

[](#phpunit-extension)

This package also provide a PHPUnit extension to make it easier to write test.

### CarbonReset

[](#carbonreset)

If you are using Carbon in your project, you might want to reset the Carbon class between each test to make sure you have a consistent state.

Register the extension in your phpunit configuration file.

```

```

This will reset your carbon class between each test and test suite like it would in `TestCass::tearDown` and `TestCass::tearDownAfterClass`.

### SetUpAutowire

[](#setupautowire)

A bit like the Service auto wiring would work via a service container, this extension allow you to autowire properties base on attribute that implement `AutowireInterface`.

Make sure to register is in your phpunit configuration file.

```

```

Once this is done, your test need to implement the `AutowiredInterface` interface so the extension will hook it.

```
namespace App\Tests;

use Draw\Component\Tester\PHPUnit\Extension\SetUpAutowire\AutowiredInterface;use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class MyTest extends KernelTestCase implements AutowiredInterface
{
}
```

Having the extension by itself doesn't do much, you need to put some attribute on the property you need to autowire.

> Note that the autowired system doesn't work on static properties.

```
namespace App\Tests;

use App\MyInterface;
use App\MyObject;
use App\MySecondObject;
use Draw\Component\Tester\PHPUnit\Extension\SetUpAutowire\AutowiredInterface;
use Draw\Component\Tester\PHPUnit\Extension\SetUpAutowire\AutowireMock;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class MyTest extends TestCase implements AutowiredInterface
{
   // Will create a mock object of MyInterface and assigned it to property.
   // This can be used in conjunction with the AutowireMockProperty (see below).
   #[AutowireMock]
   private MyInterface&MockObject $aService

   // The AutowireMockProperty will replace the aService property of $myObject.
   #[AutowireMockProperty('aService')]
   private MyObject $myObject;

   // By defaults, it will use the same property name in the current test case, but you can specify a different one using the second parameter.
   #[AutowireMockProperty('aService', 'anotherProperty')]
   private MySecondObject $mySecondObject;

   public function setUp(): void
   {
       $this->myObject = new MyObject();
       $this->mySecondObject = new MySecondObject();
   }
}
```

> This might seem a bit useless, but in a framework context using service it will more sense. The `AutowireService` from [draw/tester-bundle](https://github.com/mpoiriert/tester-bundle) is a good example of this in Symfony.

Since the auto wiring is done in the `setUp` hook of phpunit extension you cannot use them in the setup method of you test. If you need to access those property in your `setUp` method, you can use the `AutowiredCompletionAwareInterface` instead.

```
namespace App\Tests;

use App\MyService;use Draw\Bundle\TesterBundle\PHPUnit\Extension\SetUpAutowire\AutowireService;use Draw\Component\Tester\PHPUnit\Extension\SetUpAutowire\AutowiredCompletionAwareInterface;use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class MyTest extends KernelTestCase implements AutowiredCompletionAwareInterface
{
   #[AutowireMock]
   private MyInterface&MockObject $aService

    public function postAutowire(): void
    {
         $this->aService
            ->expects(static::any())
            ->method('someMethod')
            ->willReturn('someValue');
    }
}
```

#### Creating you own Autowire attribute

[](#creating-you-own-autowire-attribute)

You can create your own attribute to autowire your own property.

You just need to create an attribute that implement the `AutowireInterface` interface.

```
namespace App\Test\PHPUnit\SetUpAutowire;

use Draw\Component\Tester\PHPUnit\Extension\SetUpAutowire\AutowireInterface;use PHPUnit\Framework\TestCase;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class AutowireRandomInt implements AutowireInterface
{
    // This is the priority of the autowire. The higher the number the sooner it will be called.
    // This can be important if you need to autowire a property before another one.
    public static function getPriority(): int
    {
        return 0;
    }

    public function __construct(
       private int $min = \PHP_INT_MIN,
       private int $max = \PHP_INT_MAX
    ) {}

    public function autowire(TestCase $testCase, \ReflectionProperty $reflectionProperty): void
    {
        $reflectionProperty->setValue(
            $testCase,
            random_int($this->min, $this->max)
        );
    }
}
```

Now you can simply use it in your test case:

```
namespace App\Tests;

use App\Test\PHPUnit\SetUpAutowire\AutowireRandomInt;

class MyTest extends KernelTestCase
{
    #[AutowireRandomInt(1, 10)]
    private int $randomInt;
}
```

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance86

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% 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.

###  Release Activity

Cadence

Every ~8 days

Total

264

Last Release

77d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bb9496b48abc2bfd37ebafa9cc4b3b1307a369ad27f6514943408d9b5ff18a5?d=identicon)[mpoiriert](/maintainers/mpoiriert)

---

Top Contributors

[![mpoiriert](https://avatars.githubusercontent.com/u/4175616?v=4)](https://github.com/mpoiriert "mpoiriert (349 commits)")[![DumitracheAdrian](https://avatars.githubusercontent.com/u/12441524?v=4)](https://github.com/DumitracheAdrian "DumitracheAdrian (2 commits)")[![kiloumap](https://avatars.githubusercontent.com/u/17480546?v=4)](https://github.com/kiloumap "kiloumap (1 commits)")[![olarno](https://avatars.githubusercontent.com/u/43755813?v=4)](https://github.com/olarno "olarno (1 commits)")

---

Tags

httpphpunittestdraw

### Embed Badge

![Health badge](/badges/draw-tester/health.svg)

```
[![Health](https://phpackages.com/badges/draw-tester/health.svg)](https://phpackages.com/packages/draw-tester)
```

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)[elliotchance/concise

Concise is test framework for using plain English and minimal code, built on PHPUnit.

45223.8k4](/packages/elliotchance-concise)[bshaffer/phpunit-retry-annotations

Traits for retrying test methods and classes in PHPUnit

23482.5k2](/packages/bshaffer-phpunit-retry-annotations)

PHPackages © 2026

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