Passed
Push — master ( a53d55...43aca1 )
by Maximilian
03:50
created

LongPressTest::testConstructorWithAllParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
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\Gesture;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\GestureType;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Gesture\LongPress;
9
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand;
10
use PHPUnit\Framework\TestCase;
11
12
class LongPressTest extends TestCase
13
{
14
    public function testConstructorWithAllParameters(): void
15
    {
16
        $onLongPressStart = [$this->createMock(AbstractStandardCommand::class)];
17
        $onLongPressEnd = [$this->createMock(AbstractStandardCommand::class)];
18
        $onCancel = [$this->createMock(AbstractStandardCommand::class)];
19
        $when = false;
20
21
        $gesture = new LongPress($onLongPressStart, $onLongPressEnd, $onCancel, $when);
22
23
        $this->assertSame($onLongPressStart, $gesture->onLongPressStart);
24
        $this->assertSame($onLongPressEnd, $gesture->onLongPressEnd);
25
    }
26
27
    public function testConstructorWithDefaultParameters(): void
28
    {
29
        $gesture = new LongPress();
30
31
        $this->assertNull($gesture->onLongPressStart);
32
        $this->assertNull($gesture->onLongPressEnd);
33
    }
34
35
    public function testJsonSerializeWithAllCommands(): void
36
    {
37
        $onLongPressStart = [$this->createMock(AbstractStandardCommand::class)];
38
        $onLongPressEnd = [$this->createMock(AbstractStandardCommand::class)];
39
        $onCancel = [$this->createMock(AbstractStandardCommand::class)];
40
41
        $gesture = new LongPress($onLongPressStart, $onLongPressEnd, $onCancel, false);
42
        $result = $gesture->jsonSerialize();
43
44
        $this->assertSame(GestureType::LONG_PRESS->value, $result['type']);
45
        $this->assertSame($onLongPressStart, $result['onLongPressStart']);
46
        $this->assertSame($onLongPressEnd, $result['onLongPressEnd']);
47
        $this->assertSame($onCancel, $result['onCancel']);
48
        $this->assertFalse($result['when']);
49
    }
50
51
    public function testJsonSerializeWithEmptyArrays(): void
52
    {
53
        $gesture = new LongPress([], []);
54
        $result = $gesture->jsonSerialize();
55
56
        $this->assertArrayNotHasKey('onLongPressStart', $result);
57
        $this->assertArrayNotHasKey('onLongPressEnd', $result);
58
    }
59
60
    public function testJsonSerializeWithNullValues(): void
61
    {
62
        $gesture = new LongPress();
63
        $result = $gesture->jsonSerialize();
64
65
        $this->assertSame(GestureType::LONG_PRESS->value, $result['type']);
66
        $this->assertArrayNotHasKey('onLongPressStart', $result);
67
        $this->assertArrayNotHasKey('onLongPressEnd', $result);
68
    }
69
}
70