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

LongPressTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 30
dl 0
loc 56
rs 10
c 1
b 0
f 1
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorWithAllParameters() 0 11 1
A testJsonSerializeWithNullValues() 0 8 1
A testJsonSerializeWithAllCommands() 0 14 1
A testJsonSerializeWithEmptyArrays() 0 7 1
A testConstructorWithDefaultParameters() 0 6 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