Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add FC in ResourceIdentifier
  • Loading branch information
Art4 committed Jul 19, 2024
commit 933173024b6dc3703ec07171eb5c02d1fbc55fde
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