From 09b7ab9a42e20fffdbb27baafa2bea94a50a7c51 Mon Sep 17 00:00:00 2001 From: Alex Manase Date: Thu, 17 Nov 2022 15:43:30 +0200 Subject: [PATCH 1/2] fixes ignored dataset description for string description --- src/Datasets.php | 6 +++++- tests/.snapshots/success.txt | 4 +++- tests/Features/Datasets.php | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Datasets.php b/src/Datasets.php index 19ed1359..ca43a31c 100644 --- a/src/Datasets.php +++ b/src/Datasets.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest; use Closure; +use Generator; use Pest\Exceptions\DatasetAlreadyExist; use Pest\Exceptions\DatasetDoesNotExist; use SebastianBergmann\Exporter\Exporter; @@ -122,7 +123,10 @@ final class Datasets } if ($datasets[$index] instanceof Traversable) { - $datasets[$index] = iterator_to_array($datasets[$index], false); + $preserveKeysForArrayIterator = $datasets[$index] instanceof Generator + && is_string($datasets[$index]->key()); + + $datasets[$index] = iterator_to_array($datasets[$index], $preserveKeysForArrayIterator); } foreach ($datasets[$index] as $key => $values) { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index c1095e96..0f8280ec 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -101,6 +101,8 @@ ✓ eager registered wrapped datasets with Generator functions with (3) ✓ eager registered wrapped datasets with Generator functions with (4) ✓ eager registered wrapped datasets with Generator functions did the job right + ✓ eager registered wrapped datasets with Generator functions display description with data set "taylor" + ✓ eager registered wrapped datasets with Generator functions display description with data set "james" ✓ it can resolve a dataset after the test case is available with (Closure Object (...)) ✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #1 ✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #2 @@ -727,5 +729,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 9 skipped, 485 passed + Tests: 4 incompleted, 9 skipped, 487 passed \ No newline at end of file diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 83b47277..6839853c 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -247,6 +247,13 @@ test('eager registered wrapped datasets with Generator functions did the job rig expect($wrapped_generator_state->text)->toBe('1234'); }); +test('eager registered wrapped datasets with Generator functions display description', function ($wrapped_generator_state_with_description) { + expect($wrapped_generator_state_with_description)->not->toBeEmpty(); +})->with(function () { + yield 'taylor' => 'foo@bar.com'; + yield 'james' => 'bar@foo.com'; +}); + it('can resolve a dataset after the test case is available', function ($result) { expect($result)->toBe('bar'); })->with([ From 0a6873d8a6ee31b9b9b2df534fa5f54e79412e9c Mon Sep 17 00:00:00 2001 From: Alex Manase Date: Thu, 17 Nov 2022 16:14:03 +0200 Subject: [PATCH 2/2] wip --- tests/Features/Datasets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 6839853c..dcc7db3a 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -250,8 +250,8 @@ test('eager registered wrapped datasets with Generator functions did the job rig test('eager registered wrapped datasets with Generator functions display description', function ($wrapped_generator_state_with_description) { expect($wrapped_generator_state_with_description)->not->toBeEmpty(); })->with(function () { - yield 'taylor' => 'foo@bar.com'; - yield 'james' => 'bar@foo.com'; + yield 'taylor' => 'taylor@laravel.com'; + yield 'james' => 'james@laravel.com'; }); it('can resolve a dataset after the test case is available', function ($result) {