ergebnis / data-provider
Provides generic data providers for use with phpunit/phpunit.
Installs: 311 761
Dependents: 19
Suggesters: 0
Security: 0
Stars: 27
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- fakerphp/faker: ^1.21.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.28.3
- ergebnis/license: ^2.4.0
- ergebnis/php-cs-fixer-config: ^6.13.0
- infection/infection: ~0.26.6
- phpunit/phpunit: ^9.6.13
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.18.11
- vimeo/psalm: ^5.16.0
README
This package provides generic data providers for use with phpunit/phpunit
.
Installation
Run
composer require ergebnis/data-provider
Usage
This package provides the following generic data providers:
Ergebnis\DataProvider\BoolProvider
Ergebnis\DataProvider\FloatProvider
Ergebnis\DataProvider\IntProvider
Ergebnis\DataProvider\NullProvider
Ergebnis\DataProvider\ObjectProvider
Ergebnis\DataProvider\ResourceProvider
Ergebnis\DataProvider\StringProvider
Ergebnis\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); } }
DataProvider\BoolProvider
arbitrary()
providestrue
,false
false()
providesfalse
true()
providestrue
For examples, see Ergebnis\DataProvider\Test\Unit\BoolProviderTest
.
DataProvider\FloatProvider
arbitrary()
provides arbitraryfloat
sgreaterThanOne()
providesint
s greater than1.0
greaterThanZero()
providesint
s greater than0.0
lessThanOne()
providesint
s less than1.0
lessThanZero()
providesint
s less than0.0
one()
provides1.0
zero()
provides0.0
For examples, see Ergebnis\DataProvider\Test\Unit\FloatProviderTest
.
DataProvider\IntProvider
arbitrary()
provides arbitraryint
sgreaterThanOne()
providesint
s greater than1
greaterThanZero()
providesint
s greater than0
lessThanOne()
providesint
s less than1
lessThanZero()
providesint
s less than0
one()
provides1
zero()
provides0
For examples, see Ergebnis\DataProvider\Test\Unit\IntProviderTest
.
DataProvider\NullProvider
null()
providesnull
For examples, see Ergebnis\DataProvider\Test\Unit\NullProviderTest
.
DataProvider\ObjectProvider
object()
provides an instance ofstdClass
For examples, see Ergebnis\DataProvider\Test\Unit\ObjectProviderTest
.
DataProvider\ResourceProvider
resource()
provides aresource
For examples, see Ergebnis\DataProvider\Test\Unit\ResourceProviderTest
.
DataProvider\StringProvider
arbitrary()
provides arbitrarystring
sblank()
providesstring
s consisting of whitespace characters onlyempty()
provides an emptystring
trimmed()
provides non-empty, non-blankstrings
without leading and trailing whitespaceuntrimmed()
provides non-empty, non-blankstring
s with additional leading and trailing whitespacewithWhitespace()
provides non-empty, non-blank, trimmedstring
s containing whitespace
For examples, see Ergebnis\DataProvider\Test\Unit\StringProviderTest
.
DataProvider\UuidProvider
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
.
Changelog
The maintainers of this package record notable changes to this project in a changelog.
Contributing
The maintainers of this package suggest following the contribution guide.
Code of Conduct
The maintainers of this package ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this package provide limited support.
You can support the maintenance of this package by sponsoring @localheinz or requesting an invoice for services related to this package.
PHP Version Support Policy
This package supports PHP versions with active support.
The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version when it has reached its end of active support.
Security Policy
This package has a security policy.
License
This package uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.