From 94ebb1169c57de63da913765178c60ce7491c7ca Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 6 May 2026 01:49:05 +0100 Subject: [PATCH] Fix Volume null droplet IDs hydration --- CHANGELOG.md | 1 + src/Entity/Volume.php | 2 + tests/Entity/VolumeTest.php | 92 +++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tests/Entity/VolumeTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a4ed5d..2f892cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGE LOG * Fixed the `Droplet::create` SSH keys parameter type documentation * Fixed hydration of object-backed App Platform and project resource fields * Fixed `LoadBalancer` hydration and update serialization +* Fixed `Volume` hydration when `droplet_ids` is null ## 5.0.5 (03/05/2025) diff --git a/src/Entity/Volume.php b/src/Entity/Volume.php index 9efc8e2..d151fee 100644 --- a/src/Entity/Volume.php +++ b/src/Entity/Volume.php @@ -52,6 +52,8 @@ public function build(array $parameters): void if ('region' === $property) { $this->region = new Region($value); + } elseif ('dropletIds' === $property && null === $value) { + $this->dropletIds = []; } elseif (\property_exists($this, $property)) { $this->$property = $value; } diff --git a/tests/Entity/VolumeTest.php b/tests/Entity/VolumeTest.php new file mode 100644 index 0000000..3159523 --- /dev/null +++ b/tests/Entity/VolumeTest.php @@ -0,0 +1,92 @@ + + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DigitalOceanV2\Tests\Entity; + +use DigitalOceanV2\Entity\AbstractEntity; +use DigitalOceanV2\Entity\Region; +use DigitalOceanV2\Entity\Volume; +use PHPUnit\Framework\TestCase; + +/** + * @author Graham Campbell + */ +class VolumeTest extends TestCase +{ + public function testConstructor(): void + { + $values = [ + 'id' => '506f78a4-e098-11e5-ad9f-000f53306ae1', + 'region' => [ + 'name' => 'New York 1', + 'slug' => 'nyc1', + 'available' => true, + 'features' => [ + 'private_networking', + ], + 'sizes' => [ + 's-1vcpu-1gb', + ], + ], + 'droplet_ids' => [3164444], + 'name' => 'example', + 'description' => 'Block store for examples', + 'size_gigabytes' => 10, + 'created_at' => '2020-03-02T17:00:49Z', + 'filesystem_type' => 'ext4', + 'filesystem_label' => 'example', + 'tags' => [ + 'aninterestingtag', + ], + ]; + + $entity = new Volume($values); + + self::assertInstanceOf(AbstractEntity::class, $entity); + self::assertInstanceOf(Volume::class, $entity); + self::assertInstanceOf(Region::class, $entity->region); + self::assertSame($values['id'], $entity->id); + self::assertSame($values['droplet_ids'], $entity->dropletIds); + self::assertSame($values['name'], $entity->name); + self::assertSame($values['description'], $entity->description); + self::assertSame($values['size_gigabytes'], $entity->sizeGigabytes); + self::assertSame($values['created_at'], $entity->createdAt); + self::assertSame($values['filesystem_type'], $entity->filesystemType); + self::assertSame($values['filesystem_label'], $entity->filesystemLabel); + self::assertSame($values['tags'], $entity->tags); + } + + public function testConstructorAcceptsNullDropletIds(): void + { + $entity = new Volume([ + 'id' => '506f78a4-e098-11e5-ad9f-000f53306ae1', + 'region' => [ + 'name' => 'New York 1', + 'slug' => 'nyc1', + 'available' => true, + 'features' => [], + 'sizes' => [], + ], + 'droplet_ids' => null, + 'name' => 'example', + 'description' => 'Block store for examples', + 'size_gigabytes' => 10, + 'created_at' => '2020-03-02T17:00:49Z', + 'filesystem_type' => 'ext4', + 'filesystem_label' => 'example', + ]); + + self::assertSame([], $entity->dropletIds); + } +}