InsertItemCommandTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 46
dl 0
loc 79
rs 10
c 1
b 0
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithAllParameters() 0 16 1
A testJsonSerializeWithAllProperties() 0 15 1
A testConstructorWithDefaultParameters() 0 8 1
A testJsonSerializeWithMixedItemTypes() 0 12 1
A testJsonSerializeWithEmptyArray() 0 6 1
A testJsonSerializeWithNullValues() 0 10 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\InsertItemCommand;
8
use PHPUnit\Framework\TestCase;
9
10
class InsertItemCommandTest extends TestCase
11
{
12
    public function testConstructorWithAllParameters(): void
13
    {
14
        $at = 2;
15
        $componentId = 'myList';
16
        $item = ['type' => 'Text', 'text' => 'New Item'];
17
        $items = [
18
            ['type' => 'Text', 'text' => 'Item 1'],
19
            ['type' => 'Text', 'text' => 'Item 2'],
20
        ];
21
22
        $command = new InsertItemCommand($at, $componentId, $item, $items);
23
24
        $this->assertSame($at, $command->at);
25
        $this->assertSame($componentId, $command->componentId);
26
        $this->assertSame($item, $command->item);
27
        $this->assertSame($items, $command->items);
28
    }
29
30
    public function testConstructorWithDefaultParameters(): void
31
    {
32
        $command = new InsertItemCommand();
33
34
        $this->assertNull($command->at);
35
        $this->assertNull($command->componentId);
36
        $this->assertNull($command->item);
37
        $this->assertNull($command->items);
38
    }
39
40
    public function testJsonSerializeWithAllProperties(): void
41
    {
42
        $at = 1;
43
        $componentId = 'testList';
44
        $item = 'simple string item';
45
        $items = ['item1', 'item2'];
46
47
        $command = new InsertItemCommand($at, $componentId, $item, $items);
48
        $result = $command->jsonSerialize();
49
50
        $this->assertSame(InsertItemCommand::TYPE, $result['type']);
51
        $this->assertSame($at, $result['at']);
52
        $this->assertSame($componentId, $result['componentId']);
53
        $this->assertSame($item, $result['item']);
54
        $this->assertSame($items, $result['items']);
55
    }
56
57
    public function testJsonSerializeWithEmptyArray(): void
58
    {
59
        $command = new InsertItemCommand(null, null, null, []);
60
        $result = $command->jsonSerialize();
61
62
        $this->assertArrayNotHasKey('items', $result);
63
    }
64
65
    public function testJsonSerializeWithNullValues(): void
66
    {
67
        $command = new InsertItemCommand();
68
        $result = $command->jsonSerialize();
69
70
        $this->assertSame(InsertItemCommand::TYPE, $result['type']);
71
        $this->assertArrayNotHasKey('at', $result);
72
        $this->assertArrayNotHasKey('componentId', $result);
73
        $this->assertArrayNotHasKey('item', $result);
74
        $this->assertArrayNotHasKey('items', $result);
75
    }
76
77
    public function testJsonSerializeWithMixedItemTypes(): void
78
    {
79
        $item = ['type' => 'Component'];
80
        $items = [123, 'string', ['array' => 'value']];
81
82
        $command = new InsertItemCommand(0, 'list', $item, $items);
83
        $result = $command->jsonSerialize();
84
85
        $this->assertSame(0, $result['at']);
86
        $this->assertSame('list', $result['componentId']);
87
        $this->assertSame($item, $result['item']);
88
        $this->assertSame($items, $result['items']);
89
    }
90
}
91