From 2440001cfcd8188db521c3061ebb00f562e0f83a Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Tue, 8 Sep 2026 20:42:15 +0500 Subject: [PATCH] fix: datasets with a single named argument (#1894) --- src/Factories/TestCaseMethodFactory.php | 4 ++-- tests/.snapshots/success.txt | 3 ++- tests/Features/DatasetsTests.php | 6 ++++++ tests/Visual/Parallel.php | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 571e253b..8808cf36 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -187,8 +187,8 @@ final class TestCaseMethodFactory $attributesCode public function $methodName(...\$arguments) { - if (count(\$arguments) === 1 && \$arguments[0] instanceof __PestDatasetProviderError) { - throw \$arguments[0]->getPrevious() ?? \$arguments[0]; + if (count(\$arguments) === 1 && \$arguments[array_key_first(\$arguments)] instanceof __PestDatasetProviderError) { + throw \$arguments[array_key_first(\$arguments)]->getPrevious() ?? \$arguments[array_key_first(\$arguments)]; } return \$this->__runTest( diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index deecf6f3..ce595932 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -275,6 +275,7 @@ ✓ dataset items can mix named and sequential styles with ('Taylor', 'taylor@laravel.com') ✓ dataset items can mix named and sequential styles with ('James', 'james@laravel.com') #1 ✓ dataset items can mix named and sequential styles with ('James', 'james@laravel.com') #2 + ✓ named parameters work with a single argument with ('Taylor') PASS Tests\Features\Depends ✓ first @@ -2255,4 +2256,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1598 passed (3485 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1599 passed (3486 assertions) \ No newline at end of file diff --git a/tests/Features/DatasetsTests.php b/tests/Features/DatasetsTests.php index ec53d03f..35513c6e 100644 --- a/tests/Features/DatasetsTests.php +++ b/tests/Features/DatasetsTests.php @@ -494,3 +494,9 @@ test('dataset items can mix named and sequential styles', function (string $name ['James', 'james@laravel.com'], ['James', 'email' => 'james@laravel.com'], ]); + +test('named parameters work with a single argument', function (string $name): void { + expect($name)->toBe('Taylor'); +})->with([ + ['name' => 'Taylor'], +]); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 688475f7..3837686f 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -20,7 +20,7 @@ test('parallel', function () use ($run): void { $output = $run('--exclude-group=integration'); $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1580 passed (3430 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1581 passed (3431 assertions)'; expect($output) ->toContain("Tests: {$expected}")