Passed
Push — master ( 4b2c1a...a53d55 )
by Maximilian
02:53
created

GameEngineTest::testStartInputHandlerDirective()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 18
rs 9.8666
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\Event;
8
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\Pattern;
9
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\RecognizerDeviation;
10
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\RecognizerMatch;
11
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\RecognizerProgress;
12
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\StartInputHandlerDirective;
13
use MaxBeckers\AmazonAlexa\Response\Directives\GameEngine\StopInputHandlerDirective;
14
use PHPUnit\Framework\TestCase;
15
16
class GameEngineTest extends TestCase
17
{
18
    public function testStartInputHandlerDirective(): void
19
    {
20
        $pattern = Pattern::create(Pattern::ACTION_UP, ['gadgetId1', 'gadgetId2'], ['blue']);
21
22
        $recognizers = [
23
            'test_match' => RecognizerMatch::create([Pattern::ACTION_UP], RecognizerMatch::ANCHOR_START, false, ['gadgetId1', 'gadgetId2'], [$pattern]),
24
            'test_deviation' => RecognizerDeviation::create('test_match'),
25
            'test_progress' => RecognizerProgress::create('test_match', 5),
26
        ];
27
        $events = [
28
            'test_match' => Event::create(['test_match'], true, ['test_deviation'], Event::REPORTS_HISTORY, 1, 1000),
29
        ];
30
31
        $startInputHandlerDirective = StartInputHandlerDirective::create(5000, $recognizers, $events);
32
        $this->assertSame('GameEngine.StartInputHandler', $startInputHandlerDirective->type);
33
        $this->assertSame(5000, $startInputHandlerDirective->timeout);
34
        $this->assertSame('match', $startInputHandlerDirective->recognizers['test_match']->type);
35
        $this->assertSame(Event::REPORTS_HISTORY, $startInputHandlerDirective->events['test_match']->reports);
36
    }
37
38
    public function testPattern(): void
39
    {
40
        $pattern = Pattern::create(Pattern::ACTION_UP, ['gadgetId1', 'gadgetId2'], ['blue']);
41
        $this->assertJsonStringEqualsJsonString('{"gadgetIds":["gadgetId1","gadgetId2"],"colors":["blue"],"action":"up","repeat":null}', json_encode($pattern));
42
        $pattern = Pattern::create(Pattern::ACTION_UP, null, null, 10);
43
        $this->assertJsonStringEqualsJsonString('{"gadgetIds":null,"colors":null,"action":"up","repeat":10}', json_encode($pattern));
44
    }
45
46
    public function testStopInputHandlerDirective(): void
47
    {
48
        $startInputHandlerDirective = StopInputHandlerDirective::create('originatingRequestId');
49
        $this->assertSame('GameEngine.StopInputHandler', $startInputHandlerDirective->type);
50
        $this->assertSame('originatingRequestId', $startInputHandlerDirective->originatingRequestId);
51
    }
52
}
53