Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ CHANGE LOG
==========


## 5.0.6 (UPCOMING)

* Fixed `ProjectResource` links hydration


## 5.0.5 (03/05/2025)

* Fixed `FirewallRuleOutbound` hydration
Expand Down
11 changes: 11 additions & 0 deletions src/Entity/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ final class ProjectResource extends AbstractEntity
public array $links;

public string $status;

public function build(array $parameters): void
{
foreach ($parameters as $property => $value) {
if ('links' === static::convertToCamelCase($property) && $value instanceof \stdClass) {
$parameters[$property] = \get_object_vars($value);
}
}

parent::build($parameters);
}
}
19 changes: 19 additions & 0 deletions tests/ProjectResourceEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,23 @@ public function testConstructor(): void
self::assertSame(['self' => 'https://api.digitalocean.com/v2/droplets/123456789'], $projectResource->links);
self::assertSame('already_assigned', $projectResource->status);
}

public function testConstructorAcceptsApiShapedLinksObject(): void
{
$projectResource = new ProjectResource([
'urn' => 'do:droplet:123456789',
'assigned_at' => '2022-08-04T04:26:24Z',
'links' => (object) [
'self' => 'https://api.digitalocean.com/v2/droplets/123456789',
],
'status' => 'already_assigned',
]);

self::assertInstanceOf(AbstractEntity::class, $projectResource);
self::assertInstanceOf(ProjectResource::class, $projectResource);
self::assertSame('do:droplet:123456789', $projectResource->urn);
self::assertSame('2022-08-04T04:26:24Z', $projectResource->assignedAt);
self::assertSame(['self' => 'https://api.digitalocean.com/v2/droplets/123456789'], $projectResource->links);
self::assertSame('already_assigned', $projectResource->status);
}
}
Loading