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

ChanceStrategyTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 27
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\ChanceStrategy;
8
use PHPUnit\Framework\TestCase;
9
10
class ChanceStrategyTest extends TestCase
11
{
12
    public function testChanceStrategyUseChance(): void
13
    {
14
        $strategy = new ChanceStrategy(0.5);
15
16
        $results = [];
17
18
        for ($i = 0; $i < 10; $i++) {
19
            $results[] = $strategy->generate('some_name', fn() => true);
20
        }
21
22
        $count = 0;
23
        foreach ($results as $result) {
24
            if ($result === true) {
25
                $count++;
26
            }
27
        }
28
29
        self::assertTrue($count < 10);
30
    }
31
32
    public function testChanceStrategyWithInvalidWeight(): void
33
    {
34
        $this->expectException(\InvalidArgumentException::class);
35
36
        new ChanceStrategy(1.3);
37
    }
38
}