From 933173024b6dc3703ec07171eb5c02d1fbc55fde Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 19 Jul 2024 13:11:36 +0200 Subject: [PATCH] Add FC in ResourceIdentifier --- src/V1/ResourceIdentifier.php | 11 ++++++----- tests/Unit/V1/ResourceIdentifierTest.php | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/V1/ResourceIdentifier.php b/src/V1/ResourceIdentifier.php index 9950667..627c1ea 100644 --- a/src/V1/ResourceIdentifier.php +++ b/src/V1/ResourceIdentifier.php @@ -47,11 +47,12 @@ protected function parse(mixed $object): void throw new ValidationException('A resource id MUST be a string'); } - $this->set('type', $object->type); - $this->set('id', $object->id); - - if (property_exists($object, 'meta')) { - $this->set('meta', $this->create('Meta', $object->meta)); + foreach (get_object_vars($object) as $key => $value) { + if ($key === 'meta') { + $this->set('meta', $this->create('Meta', $value)); + } else { + $this->set($key, $value); + } } } diff --git a/tests/Unit/V1/ResourceIdentifierTest.php b/tests/Unit/V1/ResourceIdentifierTest.php index c0867f7..a5aed02 100644 --- a/tests/Unit/V1/ResourceIdentifierTest.php +++ b/tests/Unit/V1/ResourceIdentifierTest.php @@ -60,16 +60,21 @@ public function testCreateWithObjectAndMeta(): void $object->type = 'types'; $object->id = '159'; $object->meta = new \stdClass(); + $object->fc = 'test property for forward compatability'; $identifier = new ResourceIdentifier($object, $this->manager, $this->parent); $this->assertInstanceOf(ResourceIdentifier::class, $identifier); - $this->assertSame($identifier->get('type'), 'types'); - $this->assertSame($identifier->get('id'), '159'); + $this->assertSame(['type', 'id', 'meta', 'fc'], $identifier->getKeys()); + $this->assertTrue($identifier->has('type')); + $this->assertSame('types', $identifier->get('type')); + $this->assertTrue($identifier->has('id')); + $this->assertSame('159', $identifier->get('id')); $this->assertTrue($identifier->has('meta')); $this->assertInstanceOf(Accessable::class, $identifier->get('meta')); - $this->assertSame($identifier->getKeys(), ['type', 'id', 'meta']); + $this->assertTrue($identifier->has('fc')); + $this->assertSame('test property for forward compatability', $identifier->get('fc')); } /**