Test Failed
Push — main ( 99efcd...df6632 )
by Alex
14:53
created

InputActionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 4
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use App\Adventure\InputActions\InputActionInterface;
5
use App\Adventure\InputActions\InputActionTrait;
6
use App\Adventure\ActionResponses\LocationResponseInterface;
7
use App\Adventure\Location;
8
9
/**
10
 * Represents a test input action.
11
 * This class implements the InputActionInterface and uses the InputActionTrait
12
 * to provide the same functionality as the other actions used in the game.
13
 */
14
class TestAction implements InputActionInterface
15
{
16
    use InputActionTrait;
17
18
    /**
19
     * Retrieves the name that identifies the test input action.
20
     *
21
     * @return string The name representing the test input action.
22
     */
23
    public function getName(): string
24
    {
25
        return 'test';
26
    }
27
}
28
29
/**
30
 * Unit tests for input actions.
31
 * It essentially tests the functionality provided by the InputActionTrait.
32
 */
33
class InputActionTest extends TestCase
34
{
35
    /**
36
     * Test case for getName method (not provided by the trait, by the way).
37
     */
38
    public function testGetName(): void
39
    {
40
        $action = new TestAction('');
41
        $this->assertEquals('test', $action->getName());
42
    }
43
44
    /**
45
     * Test case for getTextResponse method.
46
     */
47
    public function testGetTextResponse(): void
48
    {
49
        $action = new TestAction('This is a test response');
50
        $this->assertEquals('This is a test response', $action->getTextResponse());
51
    }
52
53
    /**
54
     * Test case for setRequiredLocation and getRequiredLocation methods.
55
     */
56
    public function testSetAndGetLocationResponse(): void
57
    {
58
        $action = new TestAction('');
59
        $this->assertNull($action->getLocationResponse());
60
61
        $locationResponse = $this->createStub(LocationResponseInterface::class);
62
        $action->setLocationResponse($locationResponse);
63
64
        $this->assertSame($locationResponse, $action->getLocationResponse());
65
    }
66
67
    /**
68
     * Test case for setRequiredLocation and getRequiredLocation methods.
69
     */
70
    public function testSetAndGetRequiredLocation(): void
71
    {
72
        $action = new TestAction('');
73
        $this->assertNull($action->getRequiredLocation());
74
75
        $location = $this->createStub(Location::class);
76
        $action->setRequiredLocation($location);
77
78
        $this->assertSame($location, $action->getRequiredLocation());
79
    }
80
}
81