testConstructorWithDefaultParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 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\SendEventCommand;
8
use PHPUnit\Framework\TestCase;
9
10
class SendEventCommandTest extends TestCase
11
{
12
    public function testConstructorWithAllParameters(): void
13
    {
14
        $arguments = ['arg1' => 'value1', 'arg2' => 'value2'];
15
        $components = ['component1', 'component2'];
16
        $flags = ['interactionMode' => 'standard'];
17
18
        $command = new SendEventCommand($arguments, $components, $flags);
19
20
        $this->assertSame($arguments, $command->arguments);
21
        $this->assertSame($components, $command->components);
22
        $this->assertSame($flags, $command->flags);
23
    }
24
25
    public function testConstructorWithDefaultParameters(): void
26
    {
27
        $command = new SendEventCommand();
28
29
        $this->assertNull($command->arguments);
30
        $this->assertNull($command->components);
31
        $this->assertNull($command->flags);
32
    }
33
34
    public function testJsonSerializeWithAllProperties(): void
35
    {
36
        $arguments = ['userId' => '123', 'eventType' => 'click'];
37
        $components = ['button1', 'panel2'];
38
        $flags = ['mode' => 'interactive'];
39
40
        $command = new SendEventCommand($arguments, $components, $flags);
41
        $result = $command->jsonSerialize();
42
43
        $this->assertSame(SendEventCommand::TYPE, $result['type']);
44
        $this->assertSame($arguments, $result['arguments']);
45
        $this->assertSame($components, $result['components']);
46
        $this->assertSame($flags, $result['flags']);
47
    }
48
49
    public function testJsonSerializeWithEmptyArrays(): void
50
    {
51
        $command = new SendEventCommand([], [], []);
52
        $result = $command->jsonSerialize();
53
54
        $this->assertSame(SendEventCommand::TYPE, $result['type']);
55
        $this->assertArrayNotHasKey('arguments', $result);
56
        $this->assertArrayNotHasKey('components', $result);
57
        $this->assertArrayNotHasKey('flags', $result);
58
    }
59
60
    public function testJsonSerializeWithNullValues(): void
61
    {
62
        $command = new SendEventCommand();
63
        $result = $command->jsonSerialize();
64
65
        $this->assertSame(SendEventCommand::TYPE, $result['type']);
66
        $this->assertArrayNotHasKey('arguments', $result);
67
        $this->assertArrayNotHasKey('components', $result);
68
        $this->assertArrayNotHasKey('flags', $result);
69
    }
70
71
    public function testJsonSerializeWithPartialProperties(): void
72
    {
73
        $arguments = ['action' => 'submit'];
74
        $command = new SendEventCommand($arguments);
75
        $result = $command->jsonSerialize();
76
77
        $this->assertSame(SendEventCommand::TYPE, $result['type']);
78
        $this->assertSame($arguments, $result['arguments']);
79
        $this->assertArrayNotHasKey('components', $result);
80
        $this->assertArrayNotHasKey('flags', $result);
81
    }
82
83
    public function testJsonSerializeWithMixedArrayTypes(): void
84
    {
85
        $arguments = ['string', 123, ['nested' => 'array']];
86
        $components = [1, 'component', ['type' => 'button']];
87
        $flags = ['flag1', 'flag2' => true];
88
89
        $command = new SendEventCommand($arguments, $components, $flags);
90
        $result = $command->jsonSerialize();
91
92
        $this->assertSame($arguments, $result['arguments']);
93
        $this->assertSame($components, $result['components']);
94
        $this->assertSame($flags, $result['flags']);
95
    }
96
97
    public function testTypeConstant(): void
98
    {
99
        $this->assertSame('SendEvent', SendEventCommand::TYPE);
100
    }
101
}
102