Merge pull request #612 from alexmanase/1.x-fix-ignored-description-for-layz-datasets

[1.x] Fixes ignored dataset description only for string description
This commit is contained in:
Nuno Maduro
2022-12-07 14:23:55 +00:00
committed by GitHub
3 changed files with 15 additions and 2 deletions

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Pest; namespace Pest;
use Closure; use Closure;
use Generator;
use Pest\Exceptions\DatasetAlreadyExist; use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist; use Pest\Exceptions\DatasetDoesNotExist;
use SebastianBergmann\Exporter\Exporter; use SebastianBergmann\Exporter\Exporter;
@ -122,7 +123,10 @@ final class Datasets
} }
if ($datasets[$index] instanceof Traversable) { 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) { foreach ($datasets[$index] as $key => $values) {

View File

@ -101,6 +101,8 @@
✓ eager registered wrapped datasets with Generator functions with (3) ✓ 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 with (4)
✓ eager registered wrapped datasets with Generator functions did the job right ✓ 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 (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 (...)) #1
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #2 ✓ 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 is a test
✓ it uses correct parent class ✓ it uses correct parent class
Tests: 4 incompleted, 9 skipped, 485 passed Tests: 4 incompleted, 9 skipped, 487 passed

View File

@ -247,6 +247,13 @@ test('eager registered wrapped datasets with Generator functions did the job rig
expect($wrapped_generator_state->text)->toBe('1234'); 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' => 'taylor@laravel.com';
yield 'james' => 'james@laravel.com';
});
it('can resolve a dataset after the test case is available', function ($result) { it('can resolve a dataset after the test case is available', function ($result) {
expect($result)->toBe('bar'); expect($result)->toBe('bar');
})->with([ })->with([