From edcd2cb50e57e32bd2491c0ffb62bfb2c930a788 Mon Sep 17 00:00:00 2001 From: Stephen Shead <18731093+sshead@users.noreply.github.com> Date: Sun, 19 Jul 2020 19:05:54 +1000 Subject: [PATCH 1/3] Add name to description for named datasets --- src/Datasets.php | 11 +++++++---- tests/.snapshots/success.txt | 5 ++++- tests/Unit/Datasets.php | 13 +++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Datasets.php diff --git a/src/Datasets.php b/src/Datasets.php index 26dc9cbc..8626332e 100644 --- a/src/Datasets.php +++ b/src/Datasets.php @@ -77,10 +77,10 @@ final class Datasets $dataSetDescriptions = []; $dataSetValues = []; - foreach ($data as $values) { + foreach ($data as $key => $values) { $values = is_array($values) ? $values : [$values]; - $dataSetDescriptions[] = $description . self::getDataSetDescription($values); + $dataSetDescriptions[] = $description . self::getDataSetDescription($key, $values); $dataSetValues[] = $values; } @@ -104,12 +104,15 @@ final class Datasets } /** + * @param int|string $key * @param array $data */ - private static function getDataSetDescription(array $data): string + private static function getDataSetDescription($key, array $data): string { $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)); } } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 950cdcc4..f0d687b7 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -345,6 +345,9 @@ ✓ it throws exception when `process isolation` is true ✓ 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 ✓ it outputs the version when --version is used ✓ it do not outputs version when --version is not used @@ -385,5 +388,5 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 7 skipped, 227 passed + Tests: 7 skipped, 228 passed \ No newline at end of file diff --git a/tests/Unit/Datasets.php b/tests/Unit/Datasets.php new file mode 100644 index 00000000..2abbc582 --- /dev/null +++ b/tests/Unit/Datasets.php @@ -0,0 +1,13 @@ + [1], + 'two' => [[2]], + ])); + + $this->assertSame('test description with data set "one" (1)', $descriptions[0]); + $this->assertSame('test description with data set "two" (array(2))', $descriptions[1]); +}); From aa352317cb8de05c07b11276f92c554c90eb1f83 Mon Sep 17 00:00:00 2001 From: Stephen Shead <18731093+sshead@users.noreply.github.com> Date: Wed, 30 Sep 2020 15:39:17 +1000 Subject: [PATCH 2/3] Add a named dataset test to output to snapshot --- tests/.snapshots/success.txt | 12 +++++++----- tests/Features/Datasets.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index f0d687b7..fe5a70f1 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -6,7 +6,7 @@ ✓ not property calls PASS Tests\Expect\toBe - ✓ expect true → toBeTrue → and false → toBeFalse + ✓ expect true → toBeTrue → and false → toBeFalse ✓ strict comparisons ✓ failures ✓ not failures @@ -255,6 +255,9 @@ ✓ eager wrapped registered datasets with (1) ✓ eager wrapped registered datasets with (2) ✓ 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 (...)) ✓ 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 @@ -292,8 +295,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' → expect true → toBeTrue - ✓ get 'foo' → expect true → toBeTrue + ✓ get 'foo' → get 'bar' → expect true → toBeTrue + ✓ get 'foo' → expect true → toBeTrue WARN Tests\Features\Skip ✓ it do not skips @@ -388,5 +391,4 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 7 skipped, 228 passed - \ No newline at end of file + Tests: 7 skipped, 231 passed diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 81f41b34..54618d92 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -95,6 +95,18 @@ test('eager registered wrapped datasets did the job right', function () use ($st 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 { public $name = 1; From 36fd18bcc8770d2a51208a5df34d68e947117047 Mon Sep 17 00:00:00 2001 From: Stephen Shead <18731093+sshead@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:27:55 +1000 Subject: [PATCH 3/3] Use Expectation API --- tests/.snapshots/success.txt | 7 ++++--- tests/Unit/Datasets.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index fe5a70f1..06190d84 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -6,7 +6,7 @@ ✓ not property calls PASS Tests\Expect\toBe - ✓ expect true → toBeTrue → and false → toBeFalse + ✓ expect true → toBeTrue → and false → toBeFalse ✓ strict comparisons ✓ failures ✓ not failures @@ -295,8 +295,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' → expect true → toBeTrue - ✓ get 'foo' → expect true → toBeTrue + ✓ get 'foo' → get 'bar' → expect true → toBeTrue + ✓ get 'foo' → expect true → toBeTrue WARN Tests\Features\Skip ✓ it do not skips @@ -392,3 +392,4 @@ ✓ depends run test only once Tests: 7 skipped, 231 passed + \ No newline at end of file diff --git a/tests/Unit/Datasets.php b/tests/Unit/Datasets.php index 2abbc582..88978e41 100644 --- a/tests/Unit/Datasets.php +++ b/tests/Unit/Datasets.php @@ -8,6 +8,6 @@ it('show the names of named datasets in their description', function () { 'two' => [[2]], ])); - $this->assertSame('test description with data set "one" (1)', $descriptions[0]); - $this->assertSame('test description with data set "two" (array(2))', $descriptions[1]); + expect($descriptions[0])->toBe('test description with data set "one" (1)'); + expect($descriptions[1])->toBe('test description with data set "two" (array(2))'); });