Skip to content

Commit

Permalink
Add DataProvider.map() to ReadMe.md
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Aug 14, 2023
1 parent 47a366c commit d49acb5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Binary file added .github/assets/example/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d49acb5

Please sign in to comment.