| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,86 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace Telnyx\Exception; |
|
| 4 |
+ |
|
| 5 |
+/** |
|
| 6 |
+ * @internal |
|
| 7 |
+ * @covers \Telnyx\Exception\InvalidRequestException |
|
| 8 |
+ */ |
|
| 9 |
+final class InvalidRequestExceptionTest extends \Telnyx\TestCase |
|
| 10 |
+{
|
|
| 11 |
+ public function createFixture() |
|
| 12 |
+ {
|
|
| 13 |
+ $mock = $this->getMockForAbstractClass(ApiErrorException::class); |
|
| 14 |
+ |
|
| 15 |
+ return $mock::factory( |
|
| 16 |
+ 'message', |
|
| 17 |
+ 200, |
|
| 18 |
+ |
|
| 19 |
+ // $httpBody |
|
| 20 |
+ '{"errors":[{"code":"some_code"}]}',
|
|
| 21 |
+ |
|
| 22 |
+ // $jsonBody |
|
| 23 |
+ [ |
|
| 24 |
+ "errors" => [ |
|
| 25 |
+ [ |
|
| 26 |
+ "code" => "some_code", |
|
| 27 |
+ "title" => "some_title", |
|
| 28 |
+ "detail" => "some_detail", |
|
| 29 |
+ "source" => [ |
|
| 30 |
+ "pointer" => "/some_pointer" |
|
| 31 |
+ ], |
|
| 32 |
+ "meta" => [ |
|
| 33 |
+ "url" => "some_url" |
|
| 34 |
+ ] |
|
| 35 |
+ ] |
|
| 36 |
+ ] |
|
| 37 |
+ ], |
|
| 38 |
+ |
|
| 39 |
+ // $httpHeaders |
|
| 40 |
+ [ |
|
| 41 |
+ 'Some-Header' => 'Some Value', |
|
| 42 |
+ 'Request-Id' => 'req_test', |
|
| 43 |
+ ], |
|
| 44 |
+ |
|
| 45 |
+ // $telnyxCode |
|
| 46 |
+ 'some_code' |
|
| 47 |
+ ); |
|
| 48 |
+ |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ public function testGetters() |
|
| 52 |
+ {
|
|
| 53 |
+ $e = $this->createFixture(); |
|
| 54 |
+ |
|
| 55 |
+ static::assertSame(200, $e->getHttpStatus()); |
|
| 56 |
+ static::assertSame('{"errors":[{"code":"some_code"}]}', $e->getHttpBody());
|
|
| 57 |
+ static::assertSame([ |
|
| 58 |
+ "errors" => [ |
|
| 59 |
+ [ |
|
| 60 |
+ "code" => "some_code", |
|
| 61 |
+ "title" => "some_title", |
|
| 62 |
+ "detail" => "some_detail", |
|
| 63 |
+ "source" => [ |
|
| 64 |
+ "pointer" => "/some_pointer" |
|
| 65 |
+ ], |
|
| 66 |
+ "meta" => [ |
|
| 67 |
+ "url" => "some_url" |
|
| 68 |
+ ] |
|
| 69 |
+ ] |
|
| 70 |
+ ] |
|
| 71 |
+ ], $e->getJsonBody()); |
|
| 72 |
+ |
|
| 73 |
+ static::assertSame('Some Value', $e->getHttpHeaders()['Some-Header']);
|
|
| 74 |
+ static::assertSame('some_code', $e->getTelnyxCode());
|
|
| 75 |
+ static::assertNotNull($e->getError()); |
|
| 76 |
+ static::assertSame('some_code', $e->getError()->code);
|
|
| 77 |
+ static::assertSame('some_detail', $e->getError()->detail);
|
|
| 78 |
+ static::assertSame('some_title', $e->getError()->title);
|
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ public function testToString() |
|
| 82 |
+ {
|
|
| 83 |
+ $e = $this->createFixture(); |
|
| 84 |
+ static::assertContains('(Request req_test)', (string) $e);
|
|
| 85 |
+ } |
|
| 86 |
+} |