DiceHandTest::testReturnValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 14
rs 9.9332
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