Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Enhancement: Provide example for composition of data providers #330

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ This package provides the following generic data providers:
* [`Ergebnis\Test\Util\DataProvider\BooleanProvider`](https://github.com/ergebnis/test-util#dataproviderbooleanprovider)
* [`Ergebnis\Test\Util\DataProvider\NullProvider`](https://github.com/ergebnis/test-util#dataprovidernullprovider)

Since it is possible to use multiple `@dataProvider` annotations for test methods, these generic data providers allow for reuse and composition of data providers:

```php
<?php

declare(strict_types=1);

namespace Example\Test;

use PHPUnit\Framework;

final class ExampleTest extends Framework\TestCase
{
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::blank()
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::empty()
*
* @param string $value
*/
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\BooleanProvider`

* `arbitrary()` provides `true`, `false`
Expand Down