fix: add repeat iteration as the last argument when combined with dataset

This commit is contained in:
Katalam
2023-10-06 15:07:48 +02:00
parent 3ee5c29a00
commit ecff90da1c
2 changed files with 29 additions and 5 deletions

View File

@ -262,8 +262,9 @@ trait Testable
{ {
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
if ($method->repetitions > 1 && $method->datasets !== []) { if ($method->repetitions > 1) {
array_shift($arguments); $firstArgument = array_shift($arguments);
$arguments[] = $firstArgument;
} }
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure'); $underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');

View File

@ -17,6 +17,29 @@ test('multiple times with multiple dataset', function (int $numberA, int $number
->and([4, 5, 6])->toContain($numberB); ->and([4, 5, 6])->toContain($numberB);
})->repeat(times: 7)->with(['a' => 1, 'b' => 2, 'c' => 3], [4, 5, 6]); })->repeat(times: 7)->with(['a' => 1, 'b' => 2, 'c' => 3], [4, 5, 6]);
test('multiple times with iterator as argument', function (int $iteration) { test('multiple times with iterator', function (int $iteration) {
expect($iteration)->toBeGreaterThan(0); expect($iteration)
})->repeat(times: 8); ->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']);