|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Request; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request\GameEngine\Event\Event; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request\GameEngine\Event\InputEvent; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request\GameEngine\InputHandlerEvent; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class InputHandlerEventTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @throws \MaxBeckers\AmazonAlexa\Exception\MissingRequestDataException |
|
17
|
|
|
* @throws \MaxBeckers\AmazonAlexa\Exception\MissingRequiredHeaderException |
|
18
|
|
|
* |
|
19
|
|
|
* @covers \MaxBeckers\AmazonAlexa\Request\Request\GameEngine\InputHandlerEvent::fromAmazonRequest |
|
20
|
|
|
* @covers \MaxBeckers\AmazonAlexa\Request\Request\GameEngine\Event\Event::fromAmazonRequest |
|
21
|
|
|
* @covers \MaxBeckers\AmazonAlexa\Request\Request\GameEngine\Event\InputEvent::fromAmazonRequest |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testIntentRequest(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$requestBody = file_get_contents(__DIR__ . '/RequestData/inputHandlerEvent.json'); |
|
26
|
|
|
$request = Request::fromAmazonRequest($requestBody, 'https://s3.amazonaws.com/echo.api/echo-api-cert.pem', 'signature'); |
|
27
|
|
|
/** |
|
28
|
|
|
* @var InputHandlerEvent |
|
29
|
|
|
*/ |
|
30
|
|
|
$inputHandlerEvent = $request->request; |
|
31
|
|
|
$this->assertInstanceOf(InputHandlerEvent::class, $inputHandlerEvent); |
|
32
|
|
|
$this->assertSame('amzn1.ask.skill.0000000-0000-0000-0000-00000000000', $request->context->system->application->applicationId); |
|
33
|
|
|
$this->assertCount(1, $inputHandlerEvent->events); |
|
34
|
|
|
$this->assertIsArray($inputHandlerEvent->events); |
|
35
|
|
|
/** |
|
36
|
|
|
* @var Event |
|
37
|
|
|
*/ |
|
38
|
|
|
$event = $inputHandlerEvent->events[0]; |
|
39
|
|
|
$this->assertInstanceOf(Event::class, $event); |
|
40
|
|
|
$this->assertSame('testEvent', $event->name); |
|
41
|
|
|
$this->assertCount(2, $event->inputEvents); |
|
42
|
|
|
$this->assertIsArray($event->inputEvents); |
|
43
|
|
|
/** |
|
44
|
|
|
* @var InputEvent; |
|
45
|
|
|
*/ |
|
46
|
|
|
$inputEvent = $event->inputEvents[0]; |
|
47
|
|
|
$this->assertInstanceOf(InputEvent::class, $inputEvent); |
|
48
|
|
|
$this->assertSame('amzn1.ask.gadget.AAAAA', $inputEvent->gadgetId); |
|
49
|
|
|
$this->assertInstanceOf(\DateTime::class, $inputEvent->timestamp); |
|
50
|
|
|
$this->assertSame('2019-03-05T13:46:21+00:00', $inputEvent->timestamp->format('c')); |
|
51
|
|
|
$this->assertSame(InputEvent::ACTION_DOWN, $inputEvent->action); |
|
52
|
|
|
$this->assertSame('000000', $inputEvent->color); |
|
53
|
|
|
$this->assertSame('press', $inputEvent->feature); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|