testConstructorWithAllParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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