DiceTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateDice() 0 7 1
A testStubRollDiceLastRoll() 0 12 1
A testCreateObject() 0 8 1
1
<?php
2
3
namespace App\Dice;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Test cases for class Dice.
9
 */
10
class DiceTest extends TestCase
11
{
12
    /**
13
     * Construct object and verify that the object has the expected
14
     * properties, use no arguments.
15
     */
16
    public function testCreateDice(): void
17
    {
18
        $die = new Dice();
19
        $this->assertInstanceOf("\App\Dice\Dice", $die);
20
21
        $res = $die->getAsString();
22
        $this->assertNotEmpty($res);
23
    }
24
25
    /**
26
     * Construct object.
27
     */
28
    public function testCreateObject(): void
29
    {
30
        $dice = new Dice();
31
        $this->assertInstanceOf("\App\Dice\Dice", $dice);
32
33
        $res = $dice->getValue();
34
        $exp = null;
35
        $this->assertEquals($exp, $res);
36
    }
37
38
    /**
39
     * Create a mocked object that always returns 6.
40
     */
41
    public function testStubRollDiceLastRoll(): void
42
    {
43
        // Create a stub for the Dice class.
44
        $stub = $this->createMock(Dice::class);
45
46
        // Configure the stub.
47
        $stub->method('roll')
48
            ->willReturn(6);
49
50
        $res = $stub->roll();
51
        $exp = 6;
52
        $this->assertEquals($exp, $res);
53
    }
54
}
55