|
6 | 6 | use InvalidArgumentException;
|
7 | 7 | use Nexmo\Voice\Webhook\Error;
|
8 | 8 | use Nexmo\Voice\Webhook\Event;
|
| 9 | +use Nexmo\Voice\Webhook\Input; |
9 | 10 | use Nexmo\Voice\Webhook\Answer;
|
10 | 11 | use Nexmo\Voice\Webhook\Record;
|
11 | 12 | use PHPUnit\Framework\TestCase;
|
@@ -184,6 +185,42 @@ public function testCanGenerateANotificationPostWebhook()
|
184 | 185 | $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $notification->getTimestamp());
|
185 | 186 | }
|
186 | 187 |
|
| 188 | + public function testCanGenerateDtmfInputFromGetWebhook() |
| 189 | + { |
| 190 | + $request = $this->getRequest('dtmf-get'); |
| 191 | + $expected = $this->getRequest('dtmf-get')->getQueryParams(); |
| 192 | + |
| 193 | + /** @var Input $input */ |
| 194 | + $input = Factory::createFromRequest($request); |
| 195 | + |
| 196 | + $this->assertTrue($input instanceof Input); |
| 197 | + $this->assertSame(json_decode($expected['speech'], true), $input->getSpeech()); |
| 198 | + $this->assertSame(json_decode($expected['dtmf'], true), $input->getDtmf()); |
| 199 | + $this->assertSame($expected['from'], $input->getFrom()); |
| 200 | + $this->assertSame($expected['to'], $input->getTo()); |
| 201 | + $this->assertSame($expected['uuid'], $input->getUuid()); |
| 202 | + $this->assertSame($expected['conversation_uuid'], $input->getConversationUuid()); |
| 203 | + $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $input->getTimestamp()); |
| 204 | + } |
| 205 | + |
| 206 | + public function testCanGenerateDtmfInputFromPostWebhook() |
| 207 | + { |
| 208 | + $request = $this->getRequest('dtmf-post'); |
| 209 | + $expected = json_decode($this->getRequest('dtmf-post')->getBody()->getContents(), true); |
| 210 | + |
| 211 | + /** @var Input $input */ |
| 212 | + $input = Factory::createFromRequest($request); |
| 213 | + |
| 214 | + $this->assertTrue($input instanceof Input); |
| 215 | + $this->assertSame($expected['speech'], $input->getSpeech()); |
| 216 | + $this->assertSame($expected['dtmf'], $input->getDtmf()); |
| 217 | + $this->assertSame($expected['from'], $input->getFrom()); |
| 218 | + $this->assertSame($expected['to'], $input->getTo()); |
| 219 | + $this->assertSame($expected['uuid'], $input->getUuid()); |
| 220 | + $this->assertSame($expected['conversation_uuid'], $input->getConversationUuid()); |
| 221 | + $this->assertEquals(new \DateTimeImmutable($expected['timestamp']), $input->getTimestamp()); |
| 222 | + } |
| 223 | + |
187 | 224 | public function testThrowsExceptionOnUnknownWebhookData()
|
188 | 225 | {
|
189 | 226 | $this->expectException(\InvalidArgumentException::class);
|
|
0 commit comments