testJsonSerializeWithAllProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 19
rs 9.7666
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\AbstractStandardCommand;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\ImportPackageCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class ImportPackageCommandTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $accept = 'application/json';
16
        $name = 'myPackage';
17
        $onFail = [$this->createMock(AbstractStandardCommand::class)];
18
        $onLoad = [$this->createMock(AbstractStandardCommand::class)];
19
        $source = 'https://example.com/package';
20
        $version = '1.0.0';
21
22
        $command = new ImportPackageCommand($accept, $name, $onFail, $onLoad, $source, $version);
23
24
        $this->assertSame($accept, $command->accept);
25
        $this->assertSame($name, $command->name);
26
        $this->assertSame($onFail, $command->onFail);
27
        $this->assertSame($onLoad, $command->onLoad);
28
        $this->assertSame($source, $command->source);
29
        $this->assertSame($version, $command->version);
30
    }
31
32
    public function testConstructorWithDefaultParameters(): void
33
    {
34
        $command = new ImportPackageCommand();
35
36
        $this->assertNull($command->accept);
37
        $this->assertNull($command->name);
38
        $this->assertNull($command->onFail);
39
        $this->assertNull($command->onLoad);
40
        $this->assertNull($command->source);
41
        $this->assertNull($command->version);
42
    }
43
44
    public function testJsonSerializeWithAllProperties(): void
45
    {
46
        $accept = 'text/plain';
47
        $name = 'testPackage';
48
        $onFail = [$this->createMock(AbstractStandardCommand::class)];
49
        $onLoad = [$this->createMock(AbstractStandardCommand::class)];
50
        $source = 'https://test.com/package';
51
        $version = '2.0.0';
52
53
        $command = new ImportPackageCommand($accept, $name, $onFail, $onLoad, $source, $version);
54
        $result = $command->jsonSerialize();
55
56
        $this->assertSame(ImportPackageCommand::TYPE, $result['type']);
57
        $this->assertSame($accept, $result['accept']);
58
        $this->assertSame($name, $result['name']);
59
        $this->assertSame($onFail, $result['onFail']);
60
        $this->assertSame($onLoad, $result['onLoad']);
61
        $this->assertSame($source, $result['source']);
62
        $this->assertSame($version, $result['version']);
63
    }
64
65
    public function testJsonSerializeWithEmptyArrays(): void
66
    {
67
        $command = new ImportPackageCommand(null, null, [], []);
68
        $result = $command->jsonSerialize();
69
70
        $this->assertArrayNotHasKey('onFail', $result);
71
        $this->assertArrayNotHasKey('onLoad', $result);
72
    }
73
74
    public function testJsonSerializeWithNullValues(): void
75
    {
76
        $command = new ImportPackageCommand();
77
        $result = $command->jsonSerialize();
78
79
        $this->assertSame(ImportPackageCommand::TYPE, $result['type']);
80
        $this->assertArrayNotHasKey('accept', $result);
81
        $this->assertArrayNotHasKey('name', $result);
82
        $this->assertArrayNotHasKey('onFail', $result);
83
        $this->assertArrayNotHasKey('onLoad', $result);
84
        $this->assertArrayNotHasKey('source', $result);
85
        $this->assertArrayNotHasKey('version', $result);
86
    }
87
88
    public function testJsonSerializeWithPartialProperties(): void
89
    {
90
        $command = new ImportPackageCommand('application/json', 'partial');
91
        $result = $command->jsonSerialize();
92
93
        $this->assertSame(ImportPackageCommand::TYPE, $result['type']);
94
        $this->assertSame('application/json', $result['accept']);
95
        $this->assertSame('partial', $result['name']);
96
        $this->assertArrayNotHasKey('onFail', $result);
97
        $this->assertArrayNotHasKey('onLoad', $result);
98
        $this->assertArrayNotHasKey('source', $result);
99
        $this->assertArrayNotHasKey('version', $result);
100
    }
101
}
102