Skip to content

Commit

Permalink
Add FC in ResourceIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Jul 19, 2024
1 parent ca0b501 commit 9331730
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/V1/ResourceIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions tests/Unit/V1/ResourceIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 9331730

Please sign in to comment.