| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,63 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace Telnyx; |
|
| 4 |
+ |
|
| 5 |
+class DummyApiResource extends ApiResource |
|
| 6 |
+{
|
|
| 7 |
+ const OBJECT_NAME = 'phone_number'; |
|
| 8 |
+ |
|
| 9 |
+ // For testing nested resources |
|
| 10 |
+ public static function getSavedNestedResources() |
|
| 11 |
+ {
|
|
| 12 |
+ static $savedNestedResources = null; |
|
| 13 |
+ if (null === $savedNestedResources) {
|
|
| 14 |
+ $savedNestedResources = new Util\Set([ |
|
| 15 |
+ 'source', |
|
| 16 |
+ ]); |
|
| 17 |
+ } |
|
| 18 |
+ |
|
| 19 |
+ return $savedNestedResources; |
|
| 20 |
+ } |
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+/** |
|
| 24 |
+ * @internal |
|
| 25 |
+ * @covers \Telnyx\ApiResource |
|
| 26 |
+ */ |
|
| 27 |
+class ApiResourceTest extends \Telnyx\TestCase |
|
| 28 |
+{
|
|
| 29 |
+ public function testGetSavedNestedResources() |
|
| 30 |
+ {
|
|
| 31 |
+ $result = ApiResource::getSavedNestedResources(); |
|
| 32 |
+ |
|
| 33 |
+ static::assertInstanceOf(\Telnyx\Util\Set::class, $result); |
|
| 34 |
+ } |
|
| 35 |
+ |
|
| 36 |
+ public function testSet() |
|
| 37 |
+ {
|
|
| 38 |
+ $class = new DummyApiResource(); |
|
| 39 |
+ $class->abc = '123'; |
|
| 40 |
+ $class->source = new PhoneNumber(); |
|
| 41 |
+ |
|
| 42 |
+ static::assertSame('123', $class->abc);
|
|
| 43 |
+ static::assertInstanceOf(PhoneNumber::class, $class->source); |
|
| 44 |
+ static::assertTrue($class->source->saveWithParent); |
|
| 45 |
+ static::assertFalse($class->saveWithParent); |
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ public function testResourceUrlNullId() |
|
| 49 |
+ {
|
|
| 50 |
+ $class = new PhoneNumber(); |
|
| 51 |
+ try {
|
|
| 52 |
+ $url = $class->resourceUrl(null); |
|
| 53 |
+ static::fail('Did not raise error');
|
|
| 54 |
+ } catch (\Telnyx\Exception\UnexpectedValueException $e) {
|
|
| 55 |
+ static::assertSame( |
|
| 56 |
+ 'Could not determine which URL to request: Telnyx\PhoneNumber instance has invalid ID: ', |
|
| 57 |
+ $e->getMessage() |
|
| 58 |
+ ); |
|
| 59 |
+ } catch (\Exception $e) {
|
|
| 60 |
+ static::fail('Unexpected exception: ' . \get_class($e));
|
|
| 61 |
+ } |
|
| 62 |
+ } |
|
| 63 |
+} |