This project provides a composer package with generic data providers for use with phpunit/phpunit.
Run
composer require ergebnis/data-providerThis package provides the following generic data providers:
Ergebnis\DataProvider\BoolProviderErgebnis\DataProvider\FloatProviderErgebnis\DataProvider\IntProviderErgebnis\DataProvider\NullProviderErgebnis\DataProvider\ObjectProviderErgebnis\DataProvider\ResourceProviderErgebnis\DataProvider\StringProviderErgebnis\DataProvider\UuidProvider
Since it is possible to use multiple @dataProvider annotations or PHPUnit\Framework\Attribute\DataProviderExternal attributes for test methods, these generic data providers allow for reuse and composition of data providers:
<?php
declare(strict_types=1);
namespace Example\Test;
use Ergebnis\DataProvider;
use PHPUnit\Framework;
final class ExampleTest extends Framework\TestCase
{
/**
* @dataProvider \Ergebnis\DataProvider\StringProvider::blank()
* @dataProvider \Ergebnis\DataProvider\StringProvider::empty()
*/
public function testFromNameRejectsInvalidValueWithAnnotation(string $value): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Value can not be an empty or blank string.');
UserName::fromString($value);
}
#[Framework\DataProviderExternal(DataProvider\StringProvider::class, 'blank')]
#[Framework\DataProviderExternal(DataProvider\StringProvider::class, 'empty')]
public function testFromNameRejectsInvalidValueWithAttribute(string $value): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Value can not be an empty or blank string.');
UserName::fromString($value);
}
}arbitrary()providestrue,falsefalse()providesfalsetrue()providestrue
For examples, see Ergebnis\DataProvider\Test\Unit\BoolProviderTest.
arbitrary()provides arbitraryfloatsgreaterThanOne()providesints greater than1.0greaterThanZero()providesints greater than0.0lessThanOne()providesints less than1.0lessThanZero()providesints less than0.0one()provides1.0zero()provides0.0
For examples, see Ergebnis\DataProvider\Test\Unit\FloatProviderTest.
arbitrary()provides arbitraryintsgreaterThanOne()providesints greater than1greaterThanZero()providesints greater than0lessThanOne()providesints less than1lessThanZero()providesints less than0one()provides1zero()provides0
For examples, see Ergebnis\DataProvider\Test\Unit\IntProviderTest.
null()providesnull
For examples, see Ergebnis\DataProvider\Test\Unit\NullProviderTest.
object()provides an instance ofstdClass
For examples, see Ergebnis\DataProvider\Test\Unit\ObjectProviderTest.
resource()provides aresource
For examples, see Ergebnis\DataProvider\Test\Unit\ResourceProviderTest.
arbitrary()provides arbitrarystringsblank()providesstrings consisting of whitespace characters onlyempty()provides an emptystringtrimmed()provides non-empty, non-blankstringswithout leading and trailing whitespaceuntrimmed()provides non-empty, non-blankstrings with additional leading and trailing whitespacewithWhitespace()provides non-empty, non-blank, trimmedstrings containing whitespace
For examples, see Ergebnis\DataProvider\Test\Unit\StringProviderTest.
arbitrary()provides lower- and upper-case UUIDscaseLower()provides a lower-case UUIDscaseUpper()provides an upper-case UUIDs
For examples, see Ergebnis\DataProvider\Test\Unit\UuidProviderTest.
The maintainers of this project record notable changes to this project in a changelog.
The maintainers of this project suggest following the contribution guide.
The maintainers of this project ask contributors to follow the code of conduct.
The maintainers of this project provide limited support.
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
This project has a security policy.
This project uses the MIT license.
Follow @localheinz and @ergebnis on X.