Issues (12)

tests/Dice/DiceTest.php (1 issue)

Severity
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
     * Roll the dice and assert value is within bounds.
27
     */
28
    public function testRollDice(): void
29
    {
30
        $die = new Dice();
31
        $res = $die->roll();
0 ignored issues
show
The assignment to $res is dead and can be removed.
Loading history...
32
33
        $res = $die->getValue();
34
        $this->assertTrue($res >= 1);
35
        $this->assertTrue($res <= 6);
36
    }
37
38
    /**
39
     * Test that getValue returns the same value as returned by roll().
40
     */
41
    public function testGetValueAfterRoll(): void
42
    {
43
        $die = new Dice();
44
        $rolled = $die->roll();
45
        $this->assertSame($rolled, $die->getValue());
46
    }
47
48
    /**
49
     * Test that getValue throws an exception if the dice has not been rolled yet.
50
     */
51
    public function testGetValueThrowsException(): void
52
    {
53
        $die = new Dice();
54
        $this->expectException(\LogicException::class);
55
        $this->expectExceptionMessage("Dice has not been rolled yet.");
56
        $die->getValue();
57
    }
58
}
59