From 3ee5c29a005582a4faaee8b08f2547f18755c579 Mon Sep 17 00:00:00 2001 From: Katalam Date: Thu, 5 Oct 2023 23:07:03 +0200 Subject: [PATCH] feat: add repeat iteration as function argument if no extra dataset is provided --- src/Concerns/Testable.php | 2 +- src/Factories/TestCaseMethodFactory.php | 2 +- tests/Features/Repeat.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index e8d00588..9a618560 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -262,7 +262,7 @@ trait Testable { $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); - if ($method->repetitions > 1) { + if ($method->repetitions > 1 && $method->datasets !== []) { array_shift($arguments); } diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 4c42a557..edfa7e48 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -116,7 +116,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..614c666b 100644 --- a/tests/Features/Repeat.php +++ b/tests/Features/Repeat.php @@ -16,3 +16,7 @@ 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 as argument', function (int $iteration) { + expect($iteration)->toBeGreaterThan(0); +})->repeat(times: 8);