SequentialCommandTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonSerializeWithZeroRepeatCount() 0 7 1
A testConstructorWithAllParameters() 0 18 1
A testTypeConstant() 0 3 1
A testJsonSerializeWithAllProperties() 0 20 1
A testConstructorWithDefaultParameters() 0 9 1
A testJsonSerializeWithPartialProperties() 0 12 1
A testJsonSerializeWithNullValues() 0 11 1
A testJsonSerializeWithEmptyArrays() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\StandardCommand;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SequentialCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class SequentialCommandTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $catch = [$this->createMock(AbstractStandardCommand::class)];
16
        $commands = [
17
            $this->createMock(AbstractStandardCommand::class),
18
            $this->createMock(AbstractStandardCommand::class),
19
        ];
20
        $data = ['item1', 'item2'];
21
        $repeatCount = 3;
22
        $finally = [$this->createMock(AbstractStandardCommand::class)];
23
24
        $command = new SequentialCommand($catch, $commands, $data, $repeatCount, $finally);
25
26
        $this->assertSame($catch, $command->catch);
27
        $this->assertSame($commands, $command->commands);
28
        $this->assertSame($data, $command->data);
29
        $this->assertSame($repeatCount, $command->repeatCount);
30
        $this->assertSame($finally, $command->finally);
31
    }
32
33
    public function testConstructorWithDefaultParameters(): void
34
    {
35
        $command = new SequentialCommand();
36
37
        $this->assertNull($command->catch);
38
        $this->assertNull($command->commands);
39
        $this->assertNull($command->data);
40
        $this->assertNull($command->repeatCount);
41
        $this->assertNull($command->finally);
42
    }
43
44
    public function testJsonSerializeWithAllProperties(): void
45
    {
46
        $catch = [$this->createMock(AbstractStandardCommand::class)];
47
        $commands = [
48
            $this->createMock(AbstractStandardCommand::class),
49
            $this->createMock(AbstractStandardCommand::class),
50
        ];
51
        $data = ['value1', 'value2'];
52
        $repeatCount = 2;
53
        $finally = [$this->createMock(AbstractStandardCommand::class)];
54
55
        $command = new SequentialCommand($catch, $commands, $data, $repeatCount, $finally);
56
        $result = $command->jsonSerialize();
57
58
        $this->assertSame(SequentialCommand::TYPE, $result['type']);
59
        $this->assertSame($catch, $result['catch']);
60
        $this->assertSame($commands, $result['commands']);
61
        $this->assertSame($data, $result['data']);
62
        $this->assertSame($repeatCount, $result['repeatCount']);
63
        $this->assertSame($finally, $result['finally']);
64
    }
65
66
    public function testJsonSerializeWithEmptyArrays(): void
67
    {
68
        $command = new SequentialCommand([], [], [], null, []);
69
        $result = $command->jsonSerialize();
70
71
        $this->assertSame(SequentialCommand::TYPE, $result['type']);
72
        $this->assertArrayNotHasKey('catch', $result);
73
        $this->assertArrayNotHasKey('commands', $result);
74
        $this->assertArrayNotHasKey('data', $result);
75
        $this->assertArrayNotHasKey('finally', $result);
76
        $this->assertArrayNotHasKey('repeatCount', $result);
77
    }
78
79
    public function testJsonSerializeWithNullValues(): void
80
    {
81
        $command = new SequentialCommand();
82
        $result = $command->jsonSerialize();
83
84
        $this->assertSame(SequentialCommand::TYPE, $result['type']);
85
        $this->assertArrayNotHasKey('catch', $result);
86
        $this->assertArrayNotHasKey('commands', $result);
87
        $this->assertArrayNotHasKey('data', $result);
88
        $this->assertArrayNotHasKey('repeatCount', $result);
89
        $this->assertArrayNotHasKey('finally', $result);
90
    }
91
92
    public function testJsonSerializeWithZeroRepeatCount(): void
93
    {
94
        $command = new SequentialCommand(null, null, null, 0);
95
        $result = $command->jsonSerialize();
96
97
        $this->assertSame(SequentialCommand::TYPE, $result['type']);
98
        $this->assertSame(0, $result['repeatCount']);
99
    }
100
101
    public function testJsonSerializeWithPartialProperties(): void
102
    {
103
        $commands = [$this->createMock(AbstractStandardCommand::class)];
104
        $command = new SequentialCommand(null, $commands, null, 1);
105
        $result = $command->jsonSerialize();
106
107
        $this->assertSame(SequentialCommand::TYPE, $result['type']);
108
        $this->assertSame($commands, $result['commands']);
109
        $this->assertSame(1, $result['repeatCount']);
110
        $this->assertArrayNotHasKey('catch', $result);
111
        $this->assertArrayNotHasKey('data', $result);
112
        $this->assertArrayNotHasKey('finally', $result);
113
    }
114
115
    public function testTypeConstant(): void
116
    {
117
        $this->assertSame('Sequential', SequentialCommand::TYPE);
118
    }
119
}
120