|
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
|
|
|
|