ergebnis/test-util

This package is abandoned and no longer maintained. The author suggests using the ergebnis/data-provider package instead.

Provides a helper trait and generic data providers for tests.

Fund package maintenance!
localheinz

Installs: 1 158 642

Dependents: 45

Suggesters: 0

Security: 0

Stars: 15

Watchers: 3

Forks: 2

Open Issues: 0

1.6.0 2022-01-03 18:31 UTC

This package is auto-updated.

Last update: 2022-01-03 19:14:17 UTC


README

Integrate Prune Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads

Provides a helper trait for tests.

Installation

Run

$ composer require --dev ergebnis/test-util

Usage

Helper

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

<?php

declare(strict_types=1);

namespace Foo\Bar\Test\Unit;

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

final class BazTest extends Framework\TestCase
{
    use Util\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
<?php

declare(strict_types=1);

namespace Example\Test\Unit;

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

final class PlayerTest extends Framework\TestCase
{
    use Util\Helper;

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

        $player = new Player($name);

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

For reference, see fzaninotto/faker.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.

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.