maxbeckers /
amazon-alexa-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace MaxBeckers\AmazonAlexa\Test\Response; |
||
| 6 | |||
| 7 | use MaxBeckers\AmazonAlexa\Helper\ResponseHelper; |
||
| 8 | use MaxBeckers\AmazonAlexa\Response\Card; |
||
| 9 | use MaxBeckers\AmazonAlexa\Response\Directives\Display\RenderTemplateDirective; |
||
| 10 | use MaxBeckers\AmazonAlexa\Response\OutputSpeech; |
||
| 11 | use PHPUnit\Framework\TestCase; |
||
| 12 | |||
| 13 | class ResponseHelperTest extends TestCase |
||
| 14 | { |
||
| 15 | private const RESPOND = 'Respond'; |
||
| 16 | private const REPROMPT = 'Reprompt'; |
||
| 17 | |||
| 18 | public function testRespondText(): void |
||
| 19 | { |
||
| 20 | $responseHelper = new ResponseHelper(); |
||
| 21 | |||
| 22 | $response = $responseHelper->respond(self::RESPOND); |
||
| 23 | |||
| 24 | $this->assertInstanceOf(OutputSpeech::class, $response->response->outputSpeech); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 25 | $this->assertSame(self::RESPOND, $response->response->outputSpeech->text); |
||
| 26 | $this->assertFalse($response->response->shouldEndSession); |
||
|
0 ignored issues
–
show
|
|||
| 27 | } |
||
| 28 | |||
| 29 | public function testRespondTextEndSession(): void |
||
| 30 | { |
||
| 31 | $responseHelper = new ResponseHelper(); |
||
| 32 | |||
| 33 | $response = $responseHelper->respond(self::RESPOND, true); |
||
| 34 | |||
| 35 | $this->assertInstanceOf(OutputSpeech::class, $response->response->outputSpeech); |
||
|
0 ignored issues
–
show
|
|||
| 36 | $this->assertSame(self::RESPOND, $response->response->outputSpeech->text); |
||
| 37 | $this->assertTrue($response->response->shouldEndSession); |
||
|
0 ignored issues
–
show
|
|||
| 38 | } |
||
| 39 | |||
| 40 | public function testRespondSsml(): void |
||
| 41 | { |
||
| 42 | $responseHelper = new ResponseHelper(); |
||
| 43 | |||
| 44 | $response = $responseHelper->respondSsml(self::RESPOND); |
||
| 45 | |||
| 46 | $this->assertInstanceOf(OutputSpeech::class, $response->response->outputSpeech); |
||
|
0 ignored issues
–
show
|
|||
| 47 | $this->assertSame(self::RESPOND, $response->response->outputSpeech->ssml); |
||
| 48 | $this->assertFalse($response->response->shouldEndSession); |
||
|
0 ignored issues
–
show
|
|||
| 49 | } |
||
| 50 | |||
| 51 | public function testRespondSsmlEndSession(): void |
||
| 52 | { |
||
| 53 | $responseHelper = new ResponseHelper(); |
||
| 54 | |||
| 55 | $response = $responseHelper->respondSsml(self::RESPOND, true); |
||
| 56 | |||
| 57 | $this->assertInstanceOf(OutputSpeech::class, $response->response->outputSpeech); |
||
|
0 ignored issues
–
show
|
|||
| 58 | $this->assertSame(self::RESPOND, $response->response->outputSpeech->ssml); |
||
| 59 | $this->assertTrue($response->response->shouldEndSession); |
||
|
0 ignored issues
–
show
|
|||
| 60 | } |
||
| 61 | |||
| 62 | public function testRepromptText(): void |
||
| 63 | { |
||
| 64 | $responseHelper = new ResponseHelper(); |
||
| 65 | |||
| 66 | $response = $responseHelper->reprompt(self::REPROMPT); |
||
| 67 | |||
| 68 | $this->assertInstanceOf(OutputSpeech::class, $response->response->reprompt->outputSpeech); |
||
|
0 ignored issues
–
show
|
|||
| 69 | $this->assertSame(self::REPROMPT, $response->response->reprompt->outputSpeech->text); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function testRepromptSsml(): void |
||
| 73 | { |
||
| 74 | $responseHelper = new ResponseHelper(); |
||
| 75 | |||
| 76 | $response = $responseHelper->repromptSsml(self::REPROMPT); |
||
| 77 | |||
| 78 | $this->assertInstanceOf(OutputSpeech::class, $response->response->reprompt->outputSpeech); |
||
|
0 ignored issues
–
show
|
|||
| 79 | $this->assertSame(self::REPROMPT, $response->response->reprompt->outputSpeech->ssml); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function testCard(): void |
||
| 83 | { |
||
| 84 | $responseHelper = new ResponseHelper(); |
||
| 85 | $testCard = new Card(); |
||
| 86 | |||
| 87 | $response = $responseHelper->card($testCard); |
||
| 88 | |||
| 89 | $this->assertSame($testCard, $response->response->card); |
||
|
0 ignored issues
–
show
|
|||
| 90 | } |
||
| 91 | |||
| 92 | public function testRenderTemplateDirective(): void |
||
| 93 | { |
||
| 94 | $responseHelper = new ResponseHelper(); |
||
| 95 | $renderTemplateDirective = new RenderTemplateDirective(); |
||
| 96 | |||
| 97 | $response = $responseHelper->directive($renderTemplateDirective); |
||
| 98 | |||
| 99 | $this->assertSame($renderTemplateDirective, $response->response->directives[0]); |
||
|
0 ignored issues
–
show
|
|||
| 100 | } |
||
| 101 | |||
| 102 | public function testRenderTemplateDirectives(): void |
||
| 103 | { |
||
| 104 | $responseHelper = new ResponseHelper(); |
||
| 105 | $renderTemplateDirective1 = new RenderTemplateDirective(); |
||
| 106 | $renderTemplateDirective2 = new RenderTemplateDirective(); |
||
| 107 | |||
| 108 | $responseHelper->directive($renderTemplateDirective1); |
||
| 109 | $responseHelper->directive($renderTemplateDirective2); |
||
| 110 | |||
| 111 | $this->assertSame($renderTemplateDirective1, $responseHelper->response->response->directives[0]); |
||
|
0 ignored issues
–
show
|
|||
| 112 | $this->assertSame($renderTemplateDirective2, $responseHelper->response->response->directives[1]); |
||
| 113 | } |
||
| 114 | |||
| 115 | public function testResetResponse(): void |
||
| 116 | { |
||
| 117 | $responseHelper = new ResponseHelper(); |
||
| 118 | $response1 = $responseHelper->getResponse(); |
||
| 119 | |||
| 120 | $responseHelper->resetResponse(); |
||
| 121 | $response2 = $responseHelper->getResponse(); |
||
| 122 | |||
| 123 | $this->assertNotSame($response1, $response2); |
||
| 124 | } |
||
| 125 | |||
| 126 | public function testAddSessionAttribute(): void |
||
| 127 | { |
||
| 128 | $responseHelper = new ResponseHelper(); |
||
| 129 | |||
| 130 | $responseHelper->addSessionAttribute('key', 'val'); |
||
| 131 | |||
| 132 | $this->assertSame($responseHelper->response->sessionAttributes, ['key' => 'val']); |
||
| 133 | } |
||
| 134 | } |
||
| 135 |