Passed
Pull Request — master (#97)
by Maximilian
04:02
created

ActionTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 48
dl 0
loc 90
rs 10
c 1
b 0
f 1
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeWithDefaultEnabled() 0 6 1
A testJsonSerializeWithDisabledAction() 0 6 1
A testJsonSerializeWithAllProperties() 0 15 1
A testConstructorWithAllParameters() 0 18 1
A testImplementsJsonSerializable() 0 5 1
A testJsonSerializeWithEmptyCommands() 0 6 1
A testConstructorWithDefaultParameters() 0 9 1
A testJsonSerializeWithNullValues() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\Component;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Action;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class ActionTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $command = $this->createMock(AbstractStandardCommand::class);
16
        $commands = [
17
            $this->createMock(AbstractStandardCommand::class),
18
            $this->createMock(AbstractStandardCommand::class),
19
        ];
20
        $enabled = false;
21
        $label = 'Test Action';
22
        $name = 'testAction';
23
24
        $action = new Action($command, $commands, $enabled, $label, $name);
25
26
        $this->assertSame($command, $action->command);
27
        $this->assertSame($commands, $action->commands);
28
        $this->assertSame($enabled, $action->enabled);
29
        $this->assertSame($label, $action->label);
30
        $this->assertSame($name, $action->name);
31
    }
32
33
    public function testConstructorWithDefaultParameters(): void
34
    {
35
        $action = new Action();
36
37
        $this->assertNull($action->command);
38
        $this->assertNull($action->commands);
39
        $this->assertTrue($action->enabled);
40
        $this->assertNull($action->label);
41
        $this->assertNull($action->name);
42
    }
43
44
    public function testJsonSerializeWithAllProperties(): void
45
    {
46
        $command = $this->createMock(AbstractStandardCommand::class);
47
        $commands = [$this->createMock(AbstractStandardCommand::class)];
48
        $label = 'My Action';
49
        $name = 'myAction';
50
51
        $action = new Action($command, $commands, false, $label, $name);
52
        $result = $action->jsonSerialize();
53
54
        $this->assertSame($command, $result['command']);
55
        $this->assertSame($commands, $result['commands']);
56
        $this->assertFalse($result['enabled']);
57
        $this->assertSame($label, $result['label']);
58
        $this->assertSame($name, $result['name']);
59
    }
60
61
    public function testJsonSerializeWithDefaultEnabled(): void
62
    {
63
        $action = new Action();
64
        $result = $action->jsonSerialize();
65
66
        $this->assertArrayNotHasKey('enabled', $result);
67
    }
68
69
    public function testJsonSerializeWithDisabledAction(): void
70
    {
71
        $action = new Action(enabled: false);
72
        $result = $action->jsonSerialize();
73
74
        $this->assertFalse($result['enabled']);
75
    }
76
77
    public function testJsonSerializeWithEmptyCommands(): void
78
    {
79
        $action = new Action(commands: []);
80
        $result = $action->jsonSerialize();
81
82
        $this->assertArrayNotHasKey('commands', $result);
83
    }
84
85
    public function testJsonSerializeWithNullValues(): void
86
    {
87
        $action = new Action();
88
        $result = $action->jsonSerialize();
89
90
        $this->assertArrayNotHasKey('command', $result);
91
        $this->assertArrayNotHasKey('commands', $result);
92
        $this->assertArrayNotHasKey('label', $result);
93
        $this->assertArrayNotHasKey('name', $result);
94
    }
95
96
    public function testImplementsJsonSerializable(): void
97
    {
98
        $action = new Action();
99
100
        $this->assertInstanceOf(\JsonSerializable::class, $action);
101
    }
102
}
103