PHPackages                             digitalrevolution/phpunit-extensions - 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. digitalrevolution/phpunit-extensions

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

digitalrevolution/phpunit-extensions
====================================

A library for phpunit utility and support classes

v1.13.3(3mo ago)3100.5k↑14%2[1 issues](https://github.com/123inkt/phpunit-extensions/issues)[2 PRs](https://github.com/123inkt/phpunit-extensions/pulls)3MITPHPPHP ^8.1CI passing

Since Jul 6Pushed 2w ago1 watchersCompare

[ Source](https://github.com/123inkt/phpunit-extensions)[ Packagist](https://packagist.org/packages/digitalrevolution/phpunit-extensions)[ RSS](/packages/digitalrevolution-phpunit-extensions/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (34)Versions (28)Used By (3)

[![Minimum PHP Version](https://camo.githubusercontent.com/230588f62e4b3ba29858fcfcf1bbfe253f82c4180088091d6c7d4c6c06d80145/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d383839324246)](https://php.net/)[![Run tests](https://github.com/123inkt/phpunit-extensions/actions/workflows/test.yml/badge.svg)](https://github.com/123inkt/phpunit-extensions/actions/workflows/test.yml/badge.svg)

PHPUnit extensions
------------------

[](#phpunit-extensions)

Utility classes to make unit testing life easier.

Features
--------

[](#features)

### withConsecutive

[](#withconsecutive)

In PHPUnit 10 withConsecutive method was removed. To still be able to migrate existing codebases a replacement method:

PHPUnit &lt;= 9.5:

```
$mock->method('myMethod')->withConsecutive([123, 'foobar'], [456]);
```

PHPUnit &gt;= 9.6:

```
$mock->method('myMethod')->with(...consecutive([123, 'foobar'], [456]));
```

### Symfony controller tests

[](#symfony-controller-tests)

Testing a Symfony controller internally invokes the dependency container. A utility class to mock these classes more easily.

```
use DR\PHPUnitExtensions\Symfony\AbstractControllerTestCase;

class MyControllerTest extends AbstractControllerTestCase
{
    public function myTest(): void
    {
        $this->expectDenyAccessUnlessGranted('attribute', null, true);
        $this->expectGetUser(new User());
        $this->expectCreateForm(TextType::class);

        ($this->controller)();
    }

    public function getController() {
        return new MyController();
    }
}
```

**Methods**

- `expectGetUser`
- `expectIsGranted`
- `expectDenyAccessUnlessGranted`
- `expectCreateForm`
- `expectAddFlash`
- `expectGenerateUrl`
- `expectGenerateUrlWithConsecutive`
- `expectRedirectToRoute`
- `expectForward`
- `expectRender`

### Symfony ConstraintValidator tests

[](#symfony-constraintvalidator-tests)

TestCase for testing Symfony ConstraintValidators.

```
use DR\PHPUnitExtensions\Symfony\AbstractConstraintValidatorTestCase;

class MyConstraintValidatorTest extends AbstractConstraintValidatorTestCase
{
    public function testValidate(): void
    {
        $this->expectBuildViolation($constraint->message, ['parameter' => 123])
            ->expectSetCode(789)
            ->expectAtPath('path')
            ->expectAddViolation();

        $this->validator->validate(123, $this->constraint);
    }

    protected function getValidator(): ConstraintValidator
    {
        return new MyConstraintValidator();
    }

    protected function getConstraint(): Constraint
    {
        return new MyConstraint();
    }
}
```

**Methods**

- `assertHandlesIncorrectConstraintType`
- `expectNoViolations`
- `expectBuildViolation(): ConstraintViolationBuilderAssertion`

**ConstraintViolationBuilderAssertion**

- `expectSetInvalidValue`
- `expectSetPlural`
- `expectSetCode`
- `expectSetCause`
- `expectSetTranslationDomain`
- `expectSetParameters`
- `expectSetParameter`
- `expectSetParameterWithConsecutive`
- `expectAtPath`
- `expectAddViolation`

### ResponseAssertions trait

[](#responseassertions-trait)

The ResponseAssertions trait provides a set of assertion methods designed to streamline the testing of Symfony HTTP responses. This trait includes methods for verifying the status code, response message content and specific types of responses such as JSON responses

**Methods**

- `assertJsonResponse`
- `assertResponse`
- `assertResponseIsSuccessful`
- `assertResponseIsRedirection`
- `assertResponseIsClientError`
- `assertResponseIsServerError`

### ClockTestTrait

[](#clocktesttrait)

The ClockTestTrait provides a set of methods to manipulate the current time in tests. This trait will automatically freeze the time at the start of each test. The trait also provides methods to get the current time as timestamp or `DateTimeImmutable` object,

**Methods**

- `self::time(): int`
- `self::now(): DateTimeImmutable`
- `self::sleep(int|float $seconds): void`
- `self::assertNow()`
- `self::assertSameTime()`

### ImageTestTrait

[](#imagetesttrait)

The `ImageTestTrait` provides methods to compare two images by `binary string`, `SplFileInfo` or `resource`. (Requires `Imagick`). Internally `Imagick::compareImages()` is used to compare the images and therefore supports various image formats such as PNG, JPEG, GIF, PDF and more.

**Methods**

- `self::assertSameImage(string|SplFileInfo|resource, string|SplFileInfo|resource)`
- `self::assertNotSameImage(string|SplFileInfo|resource, string|SplFileInfo|resource)`

### PdfTestTrait

[](#pdftesttrait)

The `PdfTestTrait` provides methods to compare a `TCPDF` object against an image of `binary string`, `SplFileInfo`, `resource` or another `TCPDF` file. (Requires `Imagick` with `ghostscript` and `TCPDF`)

**Methods**

- `self::assertSamePdf(string|SplFileInfo|resource|TCPDF, TCPDF)`
- `self::assertNotSamePdf(string|SplFileInfo|resource|TCPDF, TCPDF)`.

**For both ImageTestTrait and PdfTestTrait:**

The environment variable `PHPUNIT_EXTENSIONS_IMAGE_DIFF_OUTPUT_PATH` can be set to a directory where a `diff.html` will be generated which will show the differences. Optionally, the environment variable `PHPUNIT_EXTENSIONS_IMAGE_DIFF_OUTPUT_URL` can be set to inform the user where to find the outputted `diff.html` file. This is useful when running tests in a CI environment.

About us
--------

[](#about-us)

At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? [We are looking for developers](https://www.werkenbij123inkt.nl/zoek-op-afdeling/it).

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~42 days

Recently: every ~12 days

Total

24

Last Release

119d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe1034dcdc9935e9b7f7a733490a5095282445a8526e30e9097e0782c78e24c1?d=identicon)[bram123](/maintainers/bram123)

![](https://www.gravatar.com/avatar/d144b8d21d1631a75230f12330a9cb0ef6608581a5e6989c18677ac52295e271?d=identicon)[FrankDekker](/maintainers/FrankDekker)

![](https://www.gravatar.com/avatar/20e2ae81f6cffdb8c1b1a488b7f2f70270a5d1bf2a57aae09950697ac0ef3dad?d=identicon)[123Tim](/maintainers/123Tim)

---

Top Contributors

[![frankdekker](https://avatars.githubusercontent.com/u/2179983?v=4)](https://github.com/frankdekker "frankdekker (15 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (9 commits)")[![bram123](https://avatars.githubusercontent.com/u/7457368?v=4)](https://github.com/bram123 "bram123 (6 commits)")[![cardoso123inkt](https://avatars.githubusercontent.com/u/139959874?v=4)](https://github.com/cardoso123inkt "cardoso123inkt (5 commits)")[![Dratejinn](https://avatars.githubusercontent.com/u/1586212?v=4)](https://github.com/Dratejinn "Dratejinn (1 commits)")

---

Tags

mockphpunittesttestcase

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digitalrevolution-phpunit-extensions/health.svg)

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

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k136.1M986](/packages/brianium-paratest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

30314.4k7](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

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