Skip to content

Commit

Permalink
Update ReadMe.md for flat map
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Aug 17, 2023
1 parent 0e884cb commit aa76f8a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ with `zip()`, `join()`, `cross()`, `pairs()`, `slice()`, `map()` and more.
* [`DataProvider::tuples()`](#dataprovidertuples)
* [`DataProvider::dictionary()`](#dataproviderdictionary)
* [`DataProvider.map()`](#dataprovidermap)
* [`DataProvider.flatMap()`](#dataproviderflatmap)
* [`DataProvider.slice()`](#dataproviderslice)
3. [Documentation](#documentation)
* [Functionalities](#functionalities)
Expand Down Expand Up @@ -337,6 +338,41 @@ public function folders(): DataProvider {
Notes:
- Names in `DataProvider` will be preserved.


### `DataProvider.flatMap()`

Emit multiple argument rows for a single input row in `DataProvider`.

💡 Useful for more control over regular `DataProvider::cross()`.


```php
/**
* @test
* @dataProvider colors
*/
public function test(string $shade, string color, string $thing): void {
// your test here
}

public function shadedColors(): DataProvider {
return $this->colors()->flatMap(function (string $color, string $thing): array {
return [
'light' => ['light', $color, $thing],
'dark' => ['dark', $color, $thing],
];
});
}

public function colors(): DataProvider {
return DataProvider::tuples(
['blue', 'sky'],
['yellow', 'sun'],
['red', 'apple']
);
}
```

### `DataProvider.slice()`

Remove leading or trailing rows from `DataProvider`.
Expand Down

0 comments on commit aa76f8a

Please sign in to comment.