mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 06:13:35 +02:00
Fix repeat with named dataset arguments (#1769)
This commit is contained in:
@@ -408,16 +408,25 @@ trait Testable
|
||||
private function __resolveTestArguments(array $arguments): array
|
||||
{
|
||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||
|
||||
if ($method->repetitions > 1) {
|
||||
$firstArgument = array_shift($arguments);
|
||||
$arguments[] = $firstArgument;
|
||||
}
|
||||
|
||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
||||
$testParameterTypesByName = Reflection::getFunctionArguments($underlyingTest);
|
||||
$testParameterTypes = array_values($testParameterTypesByName);
|
||||
|
||||
if ($method->repetitions > 1) {
|
||||
$firstArgument = array_shift($arguments);
|
||||
|
||||
if (array_is_list($arguments)) {
|
||||
$arguments[] = $firstArgument;
|
||||
} else {
|
||||
$testParameterNames = array_keys($testParameterTypesByName);
|
||||
$iterationParameterName = $testParameterNames[count($arguments)] ?? null;
|
||||
|
||||
if ($iterationParameterName !== null) {
|
||||
$arguments[$iterationParameterName] = $firstArgument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arguments) !== 1) {
|
||||
foreach ($arguments as $argumentIndex => $argumentValue) {
|
||||
if (! $argumentValue instanceof Closure) {
|
||||
|
||||
@@ -1455,6 +1455,14 @@
|
||||
✓ multiple times with repeat iterator with multiple dataset ('c') / ('d') @ repetition 2 of 2
|
||||
✓ multiple times with repeat iterator with multiple dataset ('c') / ('e') @ repetition 2 of 2
|
||||
✓ multiple times with repeat iterator with multiple dataset ('c') / ('f') @ repetition 2 of 2
|
||||
✓ multiple times with named dataset arguments ('Taylor', 'taylor@laravel.com') @ repetition 1 of 2
|
||||
✓ multiple times with named dataset arguments ('Nuno', 'enunomaduro@gmail.com') @ repetition 1 of 2
|
||||
✓ multiple times with named dataset arguments ('Taylor', 'taylor@laravel.com') @ repetition 2 of 2
|
||||
✓ multiple times with named dataset arguments ('Nuno', 'enunomaduro@gmail.com') @ repetition 2 of 2
|
||||
✓ multiple times with named dataset arguments and repeat iterator ('Taylor', 'taylor@laravel.com') @ repetition 1 of 2
|
||||
✓ multiple times with named dataset arguments and repeat iterator ('Nuno', 'enunomaduro@gmail.com') @ repetition 1 of 2
|
||||
✓ multiple times with named dataset arguments and repeat iterator ('Taylor', 'taylor@laravel.com') @ repetition 2 of 2
|
||||
✓ multiple times with named dataset arguments and repeat iterator ('Nuno', 'enunomaduro@gmail.com') @ repetition 2 of 2
|
||||
✓ describe blocks → multiple times @ repetition 1 of 3
|
||||
✓ describe blocks → multiple times @ repetition 2 of 3
|
||||
✓ describe blocks → multiple times @ repetition 3 of 3
|
||||
@@ -2226,4 +2234,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, 1573 passed (3414 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1581 passed (3434 assertions)
|
||||
|
||||
@@ -44,6 +44,28 @@ test('multiple times with repeat iterator with multiple dataset', function (stri
|
||||
->toBeGreaterThan(0);
|
||||
})->repeat(times: 2)->with(['a', 'b', 'c'], ['d', 'e', 'f']);
|
||||
|
||||
test('multiple times with named dataset arguments', function (string $name, string $email): void {
|
||||
expect($name)
|
||||
->toBeIn(['Taylor', 'Nuno'])
|
||||
->and($email)
|
||||
->toContain('@');
|
||||
})->repeat(times: 2)->with([
|
||||
['name' => 'Taylor', 'email' => 'taylor@laravel.com'],
|
||||
['name' => 'Nuno', 'email' => 'enunomaduro@gmail.com'],
|
||||
]);
|
||||
|
||||
test('multiple times with named dataset arguments and repeat iterator', function (string $name, string $email, int $iteration): void {
|
||||
expect($name)
|
||||
->toBeIn(['Taylor', 'Nuno'])
|
||||
->and($email)
|
||||
->toContain('@')
|
||||
->and($iteration)
|
||||
->toBeIn([1, 2]);
|
||||
})->repeat(times: 2)->with([
|
||||
['name' => 'Taylor', 'email' => 'taylor@laravel.com'],
|
||||
['name' => 'Nuno', 'email' => 'enunomaduro@gmail.com'],
|
||||
]);
|
||||
|
||||
describe('describe blocks', function (): void {
|
||||
test('multiple times', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
|
||||
@@ -26,13 +26,13 @@ test('parallel', function () use ($run): void {
|
||||
$file = file_get_contents(__FILE__);
|
||||
$file = preg_replace(
|
||||
'/\$expected = \'.*?\';/',
|
||||
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1555 passed (3359 assertions)';",
|
||||
"\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1563 passed (3379 assertions)';",
|
||||
$file,
|
||||
);
|
||||
file_put_contents(__FILE__, $file);
|
||||
}
|
||||
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1555 passed (3359 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1563 passed (3379 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
Reference in New Issue
Block a user