diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index c6fb49af..43d0a162 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -265,7 +265,12 @@ trait Testable $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); if ($method->repetitions > 1) { - array_shift($arguments); + // If the test is repeated, the first argument is the iteration number + // we need to move it to the end of the arguments list + // so that the datasets are the first n arguments + // and the iteration number is the last argument + $firstArgument = array_shift($arguments); + $arguments[] = $firstArgument; } $underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure'); diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index a5055ff1..e00da683 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -117,7 +117,7 @@ final class TestCaseMethodFactory */ public function receivesArguments(): bool { - return $this->datasets !== [] || $this->depends !== []; + return $this->datasets !== [] || $this->depends !== [] || $this->repetitions > 1; } /** diff --git a/tests/Features/Repeat.php b/tests/Features/Repeat.php index e0651d33..811c1185 100644 --- a/tests/Features/Repeat.php +++ b/tests/Features/Repeat.php @@ -16,3 +16,30 @@ test('multiple times with multiple dataset', function (int $numberA, int $number expect([1, 2, 3])->toContain($numberA) ->and([4, 5, 6])->toContain($numberB); })->repeat(times: 7)->with(['a' => 1, 'b' => 2, 'c' => 3], [4, 5, 6]); + +test('multiple times with iterator', function (int $iteration) { + expect($iteration) + ->toBeNumeric() + ->toBeGreaterThan(0); +})->repeat(times: 2); + +test('multiple times with repeat iterator with single dataset', function (string $letter, int $iteration) { + expect($letter) + ->toBeString() + ->toBeIn(['a', 'b', 'c']) + ->and($iteration) + ->toBeNumeric() + ->toBeGreaterThan(0); +})->repeat(times: 2)->with(['a', 'b', 'c']); + +test('multiple times with repeat iterator with multiple dataset', function (string $letterA, string $letterB, int $iteration) { + expect($letterA) + ->toBeString() + ->toBeIn(['a', 'b', 'c']) + ->and($letterB) + ->toBeString() + ->toBeIn(['d', 'e', 'f']) + ->and($iteration) + ->toBeNumeric() + ->toBeGreaterThan(0); +})->repeat(times: 2)->with(['a', 'b', 'c'], ['d', 'e', 'f']);