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

UniqueStrategyTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 22
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\UniqueStrategy;
8
use PHPUnit\Framework\TestCase;
9
10
class UniqueStrategyTest extends TestCase
11
{
12
    public function testUniqueStrategyIsUnique(): void
13
    {
14
        $strategy = new UniqueStrategy(1000);
15
16
        $results = [];
17
18
        for ($i = 0; $i < 10; $i++) {
19
            $results[] = $strategy->generate('some_name', fn() => random_int(1, 10));
20
        }
21
22
        self::assertCount(10, array_unique($results));
23
    }
24
25
    public function testUniqueStrategyHitRetriesLimit(): void
26
    {
27
        $this->expectException(\OverflowException::class);
28
        $strategy = new UniqueStrategy(3);
29
30
        for ($i = 0; $i < 100; $i++) {
31
            $strategy->generate('some_name', fn() => random_int(1, 10));
32
        }
33
    }
34
}