diff --git a/.github/assets/example/map.png b/.github/assets/example/map.png new file mode 100644 index 0000000..c106e6f Binary files /dev/null and b/.github/assets/example/map.png differ diff --git a/ReadMe.md b/ReadMe.md index 998ad80..34e99f3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -3,7 +3,7 @@ # Helper for PhpUnit @dataProvider Handy `require-dev` testing tool for [PhpUnit]. It allows to manage data providers -with `zip()`, `join()`, `cross()`, `pairs()`, `slice()` and more. +with `zip()`, `join()`, `cross()`, `pairs()`, `slice()`, `map()` and more. [![Build Status](https://github.com/t-regx/CrossDataProviders/workflows/build/badge.svg?branch=master)][build] [![Coverage Status](https://coveralls.io/repos/github/t-regx/CrossDataProviders/badge.svg?branch=master)][coveralls] @@ -32,6 +32,7 @@ with `zip()`, `join()`, `cross()`, `pairs()`, `slice()` and more. * [`DataProvider::of()`](#dataproviderof) * [`DataProvider::tuples()`](#dataprovidertuples) * [`DataProvider::dictionary()`](#dataproviderdictionary) + * [`DataProvider.map()`](#dataprovidermap) 3. [Documentation](#documentation) * [Functionalities](#functionalities) * [Features](#features) @@ -298,6 +299,43 @@ public function ports(): DataProvider { } ``` +### `DataProvider.map()` + +Transform each row's values in `DataProvider` to any other set of values. + +💡 Useful for separating providers content and their form. + +```php +/** +* @test +* @dataProvider folderIterators +*/ +public function test(\Iterator $iterator, string $name): void { + // your test here +} + +public function folderIterators(): DataProvider { + return $this->folders()->map(function (array $values): array { + return [ + new \DirectoryIterator($values[1]), + $values[0] + ]; + }); +} + +public function folders(): DataProvider { + return DataProvider::tuples( + ['temporary', '/tmp'], + ['user directory', '/home'], + ['system resources', '/usr/bin']); +} +``` + +![map.png](.github/assets/example/map.png) + +Notes: + - Names in `DataProvider` will be preserved. + # Documentation ### Functionalities