Merge pull request #134 from sshead/adds-dataset-names

Add name to description for named datasets
This commit is contained in:
Nuno Maduro
2020-10-03 17:39:26 +02:00
committed by GitHub
4 changed files with 39 additions and 5 deletions

View File

@ -77,10 +77,10 @@ final class Datasets
$dataSetDescriptions = []; $dataSetDescriptions = [];
$dataSetValues = []; $dataSetValues = [];
foreach ($data as $values) { foreach ($data as $key => $values) {
$values = is_array($values) ? $values : [$values]; $values = is_array($values) ? $values : [$values];
$dataSetDescriptions[] = $description . self::getDataSetDescription($values); $dataSetDescriptions[] = $description . self::getDataSetDescription($key, $values);
$dataSetValues[] = $values; $dataSetValues[] = $values;
} }
@ -104,12 +104,15 @@ final class Datasets
} }
/** /**
* @param int|string $key
* @param array<int, mixed> $data * @param array<int, mixed> $data
*/ */
private static function getDataSetDescription(array $data): string private static function getDataSetDescription($key, array $data): string
{ {
$exporter = new Exporter(); $exporter = new Exporter();
return \sprintf(' with (%s)', $exporter->shortenedRecursiveExport($data)); $nameInsert = is_string($key) ? \sprintf('data set "%s" ', $key) : '';
return \sprintf(' with %s(%s)', $nameInsert, $exporter->shortenedRecursiveExport($data));
} }
} }

View File

@ -255,6 +255,9 @@
✓ eager wrapped registered datasets with (1) ✓ eager wrapped registered datasets with (1)
✓ eager wrapped registered datasets with (2) ✓ eager wrapped registered datasets with (2)
✓ eager registered wrapped datasets did the job right ✓ eager registered wrapped datasets did the job right
✓ named datasets with data set "one" (1)
✓ named datasets with data set "two" (2)
✓ named datasets did the job right
✓ lazy named datasets with (Bar Object (...)) ✓ lazy named datasets with (Bar Object (...))
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #1 ✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #1
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #2 ✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #2
@ -345,6 +348,9 @@
✓ it throws exception when `process isolation` is true ✓ it throws exception when `process isolation` is true
✓ it do not throws exception when `process isolation` is false ✓ it do not throws exception when `process isolation` is false
PASS Tests\Unit\Datasets
✓ it show the names of named datasets in their description
PASS Tests\Unit\Plugins\Version PASS Tests\Unit\Plugins\Version
✓ it outputs the version when --version is used ✓ it outputs the version when --version is used
✓ it do not outputs version when --version is not used ✓ it do not outputs version when --version is not used
@ -385,5 +391,5 @@
✓ depends with defined arguments ✓ depends with defined arguments
✓ depends run test only once ✓ depends run test only once
Tests: 7 skipped, 227 passed Tests: 7 skipped, 231 passed

View File

@ -95,6 +95,18 @@ test('eager registered wrapped datasets did the job right', function () use ($st
expect($state->text)->toBe('1212121212'); expect($state->text)->toBe('1212121212');
}); });
test('named datasets', function ($text) use ($state, $datasets) {
$state->text .= $text;
expect($datasets)->toContain([$text]);
})->with([
'one' => [1],
'two' => [2],
]);
test('named datasets did the job right', function () use ($state) {
expect($state->text)->toBe('121212121212');
});
class Bar class Bar
{ {
public $name = 1; public $name = 1;

13
tests/Unit/Datasets.php Normal file
View File

@ -0,0 +1,13 @@
<?php
use Pest\Datasets;
it('show the names of named datasets in their description', function () {
$descriptions = array_keys(Datasets::resolve('test description', [
'one' => [1],
'two' => [[2]],
]));
expect($descriptions[0])->toBe('test description with data set "one" (1)');
expect($descriptions[1])->toBe('test description with data set "two" (array(2))');
});