DiceHandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 22
c 1
b 0
f 1
dl 0
loc 41
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddStubbedDices() 0 17 1
A testReturnValues() 0 14 1
1
<?php
2
3
namespace App\Dice;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Test cases for class DiceHand.
9
 */
10
class DiceHandTest extends TestCase
11
{
12
    /**
13
     * Stub the dices to assure the value can be asserted.
14
     */
15
    public function testAddStubbedDices(): void
16
    {
17
        // Create a stub for the Dice class.
18
        $stub = $this->createMock(Dice::class);
19
20
        // Configure the stub.
21
        $stub->method('roll')
22
            ->willReturn(6);
23
        $stub->method('getValue')
24
            ->willReturn(6);
25
26
        $dicehand = new DiceHand();
27
        $dicehand->add(clone $stub);
28
        $dicehand->add(clone $stub);
29
        $dicehand->roll();
30
        $res = $dicehand->sum();
31
        $this->assertEquals(12, $res);
32
    }
33
34
    /**
35
     * Test functions to return values.
36
     */
37
    public function testReturnValues(): void
38
    {
39
        $stub = $this->createMock(Dice::class);
40
        $hand = new DiceHand();
41
        $hand->add(clone $stub);
42
        $res = $hand->getValues();
43
        $this->assertNotEmpty($res);
44
45
        $hand->add(clone $stub);
46
        $res = $hand->getNumberDices();
47
        $this->assertEquals(2, $res);
48
49
        $res = $hand->getString();
50
        $this->assertNotEmpty($res);
51
52
    }
53
}
54