Provides utilities for tests.

Fund package maintenance!

1.1.0 2020-08-30 10:56 UTC


Integrate Prune Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads

Provides utilities for tests.



$ composer require --dev ergebnis/test-util


Import the Ergebnis\Test\Util\Helper trait into your test class:



namespace Foo\Bar\Test\Unit;

use Ergebnis\Test\Util\Helper;
use PHPUnit\Framework;

final class BazTest extends Framework\TestCase
    use Helper;

Easy access to localized instances of Faker\Generator

The Helper trait provides a method to fetch a localized instance of Faker\Generator:

  • faker(string $locale = 'en_US') : \Faker\Generator


namespace Example\Test\Unit;

use Ergebnis\Test\Util\Helper;
use Example\Player;
use PHPUnit\Framework;

final class PlayerTest extends Framework\TestCase
    use Helper;

    public function testConstructorSetsValues(): void
        $name = self::faker()->firstName;

        $player = new Player($name);

        $this->assertSame($name, $player->firstName());

For reference, see fzaninotto/faker.

Additional Assertions

In addition to the assertions made available by extending from PHPUnit\Framework\TestCase, the Helper trait provides the following assertions:

  • assertClassesAreAbstractOrFinal(string $directory, array $excludeClassNames = [])
  • assertClassesHaveTests(string $directory, string $namespace, string $testNamespace, array $excludeClassyNames = [])
  • assertClassExists(string $className)
  • assertClassExtends(string $parentClassName, string $className)
  • assertClassImplementsInterface(string $interfaceName, string $className)
  • assertClassIsAbstract(string $className)
  • assertClassIsFinal(string $className)
  • assertClassSatisfiesSpecification(callable $specification, string $className, string $message = '')
  • assertClassUsesTrait(string $traitName, string $className)
  • assertClassyConstructsSatisfySpecification(callable $specification, string $directory, array $excludeClassNames = [], $message = '')
  • assertInterfaceExists(string $interfaceName)
  • assertInterfaceExtends(string $parentInterfaceName, string $interfaceName)
  • assertInterfaceSatisfiesSpecification(callable $specification, string $interfaceName, string $message = '')
  • assertTraitExists(string $traitName)
  • assertTraitSatisfiesSpecification(callable $specification, string $traitName, string $message = '')


Please have a look at


Please have a look at

Code of Conduct

Please have a look at


This package is licensed using the MIT License.

Please have a look at


The SrcCodeTest in this and other projects I maintain or contribute to is inspired by ProjectCodeTest in friends-of-php/php-cs-fixer, and was initially created by Dariusz Rumiński.

Curious what I am building?

📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.