DiceHandTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddAndGetNumberDices() 0 7 1
A testRollAndGetValues() 0 16 2
A testGetString() 0 15 2
1
<?php
2
3
namespace App\Tests\Dice;
4
5
use PHPUnit\Framework\TestCase;
6
use App\Dice\Dice;
7
use App\Dice\DiceHand;
8
9
/**
10
 * Test cases for class DiceHand.
11
 */
12
class DiceHandTest extends TestCase
13
{
14
    /**
15
    * Test adding dice to the hand and counting them.
16
    */
17
    public function testAddAndGetNumberDices(): void
18
    {
19
        $hand = new DiceHand();
20
        $hand->add(new Dice());
21
        $hand->add(new Dice());
22
23
        $this->assertEquals(2, $hand->getNumberDices());
24
    }
25
26
    /**
27
     * Test dice roll and get values.
28
     */
29
    public function testRollAndGetValues(): void
30
    {
31
        $hand = new DiceHand();
32
        $die1 = new Dice();
33
        $die2 = new Dice();
34
35
        $hand->add($die1);
36
        $hand->add($die2);
37
38
        $hand->roll();
39
        $values = $hand->getValues();
40
41
        $this->assertCount(2, $values);
42
        foreach ($values as $value) {
43
            $this->assertGreaterThanOrEqual(1, $value);
44
            $this->assertLessThanOrEqual(6, $value);
45
        }
46
    }
47
48
    /**
49
     * Test getString.
50
     */
51
    public function testGetString(): void
52
    {
53
        $hand = new DiceHand();
54
        $die1 = new Dice();
55
        $die2 = new Dice();
56
57
        $hand->add($die1);
58
        $hand->add($die2);
59
60
        $hand->roll();
61
        $strings = $hand->getString();
62
63
        $this->assertCount(2, $strings);
64
        foreach ($strings as $str) {
65
            $this->assertNotEmpty($str);
66
        }
67
    }
68
}
69