|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Intent; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Intent\Intent; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Intent\Slot; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class IntentTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testWithoutResolutions(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$json = file_get_contents(__DIR__ . '/Data/intent_without_resolutions.json'); |
|
16
|
|
|
$intent = Intent::fromAmazonRequest(json_decode($json, true)); |
|
17
|
|
|
$this->assertJsonStringEqualsJsonString($json, json_encode($intent)); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testWithResolutions(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$json = file_get_contents(__DIR__ . '/Data/intent_resolution.json'); |
|
23
|
|
|
$intent = Intent::fromAmazonRequest(json_decode($json, true)); |
|
24
|
|
|
$this->assertJsonStringEqualsJsonString($json, json_encode($intent)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetResolutionByName(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$json = file_get_contents(__DIR__ . '/Data/intent_without_resolutions.json'); |
|
30
|
|
|
$intent = Intent::fromAmazonRequest(json_decode($json, true)); |
|
31
|
|
|
$slot = $intent->getSlotByName('Age'); |
|
32
|
|
|
$this->assertInstanceOf(Slot::class, $slot); |
|
33
|
|
|
$this->assertSame('Age', $slot->name); |
|
34
|
|
|
$slot = $intent->getSlotByName('age'); |
|
35
|
|
|
$this->assertNull($slot); |
|
36
|
|
|
$slot = $intent->getSlotByName('Gender'); |
|
37
|
|
|
$this->assertInstanceOf(Slot::class, $slot); |
|
38
|
|
|
$this->assertSame('Gender', $slot->name); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|