Merge pull request #620 from alexmanase/2.x-fix-ignored-description-for-lazy-datasets

[2.x] Fix: ignored dataset description for string description
This commit is contained in:
Nuno Maduro
2022-12-23 23:01:45 +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\Repositories;
use Closure;
use Generator;
use Pest\Exceptions\DatasetAlreadyExists;
use Pest\Exceptions\DatasetDoesNotExist;
use Pest\Exceptions\ShouldNotHappen;
@ -155,7 +156,10 @@ final class DatasetsRepository
}
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) {

View File

@ -107,6 +107,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 (...)) #1
✓ it can resolve a dataset after the test case is available with (Closure Object (...)) #2
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (...)) #1
@ -897,4 +899,4 @@
PASS Tests\Visual\Version
✓ visual snapshot of help command output
Tests: 4 incomplete, 2 todos, 18 skipped, 622 passed (1509 assertions)

View File

@ -249,6 +249,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' => 'taylor@laravel.com';
yield 'james' => 'james@laravel.com';
});
it('can resolve a dataset after the test case is available', function ($result) {
expect($result)->toBe('bar');
})->with([