data-provider
Installation
Run
composer require --dev 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
Since it is possible to use multiple @dataProvider
annotations for test methods, these generic data providers allow for reuse and composition of data providers:
declare(strict_types=1);
namespace Example\Test;
use PHPUnit\Framework;
final class ExampleTest extends Framework\TestCase
{
/**
* @dataProvider \Ergebnis\DataProvider\StringProvider::blank()
* @dataProvider \Ergebnis\DataProvider\StringProvider::empty()
*/
public function testFromNameRejectsBlankOrEmptyStrings(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
.
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?