| Total Complexity | 6 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class ValidStrategyTest extends TestCase |
||
| 11 | { |
||
| 12 | public function testValidStrategyIsValid(): void |
||
| 13 | { |
||
| 14 | $strategy = new ValidStrategy(fn($x) => $x <= 50); |
||
| 15 | |||
| 16 | $results = []; |
||
| 17 | |||
| 18 | for ($i = 0; $i < 10; $i++) { |
||
| 19 | $results[] = $strategy->generate('some_name', fn() => random_int(1, 1000)); |
||
| 20 | } |
||
| 21 | |||
| 22 | $count = 0; |
||
| 23 | foreach ($results as $result) { |
||
| 24 | if ($result > 50) { |
||
| 25 | $count++; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | self::assertEquals(0, $count); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testValidStrategyHitRetriesLimit(): void |
||
| 33 | { |
||
| 34 | $this->expectException(\OverflowException::class); |
||
| 35 | |||
| 36 | $strategy = new ValidStrategy(fn($x) => $x <= 50, 3); |
||
| 37 | |||
| 38 | for ($i = 0; $i < 10; $i++) { |
||
| 39 | $strategy->generate('some_name', fn() => random_int(1, 1000)); |
||
| 40 | } |
||
| 43 |