Passed
Push — main ( b1fbff...0e72dc )
by Johny
02:35
created

ValidStrategyTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 30
c 0
b 0
f 0
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DummyGenerator\Test\Strategy;
6
7
use DummyGenerator\Strategy\ValidStrategy;
8
use PHPUnit\Framework\TestCase;
9
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
        }
41
    }
42
}
43