Skip to content

Commit dbece58

Browse files
Fix Volume null droplet IDs hydration (#361)
1 parent f3ae30c commit dbece58

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGE LOG
88
* Fixed the `Droplet::create` SSH keys parameter type documentation
99
* Fixed hydration of object-backed App Platform and project resource fields
1010
* Fixed `LoadBalancer` hydration and update serialization
11+
* Fixed `Volume` hydration when `droplet_ids` is null
1112

1213

1314
## 5.0.5 (03/05/2025)

src/Entity/Volume.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function build(array $parameters): void
5252

5353
if ('region' === $property) {
5454
$this->region = new Region($value);
55+
} elseif ('dropletIds' === $property && null === $value) {
56+
$this->dropletIds = [];
5557
} elseif (\property_exists($this, $property)) {
5658
$this->$property = $value;
5759
}

tests/Entity/VolumeTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the DigitalOcean API library.
7+
*
8+
* (c) Antoine Kirk <contact@sbin.dk>
9+
* (c) Graham Campbell <hello@gjcampbell.co.uk>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace DigitalOceanV2\Tests\Entity;
16+
17+
use DigitalOceanV2\Entity\AbstractEntity;
18+
use DigitalOceanV2\Entity\Region;
19+
use DigitalOceanV2\Entity\Volume;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* @author Graham Campbell <hello@gjcampbell.co.uk>
24+
*/
25+
class VolumeTest extends TestCase
26+
{
27+
public function testConstructor(): void
28+
{
29+
$values = [
30+
'id' => '506f78a4-e098-11e5-ad9f-000f53306ae1',
31+
'region' => [
32+
'name' => 'New York 1',
33+
'slug' => 'nyc1',
34+
'available' => true,
35+
'features' => [
36+
'private_networking',
37+
],
38+
'sizes' => [
39+
's-1vcpu-1gb',
40+
],
41+
],
42+
'droplet_ids' => [3164444],
43+
'name' => 'example',
44+
'description' => 'Block store for examples',
45+
'size_gigabytes' => 10,
46+
'created_at' => '2020-03-02T17:00:49Z',
47+
'filesystem_type' => 'ext4',
48+
'filesystem_label' => 'example',
49+
'tags' => [
50+
'aninterestingtag',
51+
],
52+
];
53+
54+
$entity = new Volume($values);
55+
56+
self::assertInstanceOf(AbstractEntity::class, $entity);
57+
self::assertInstanceOf(Volume::class, $entity);
58+
self::assertInstanceOf(Region::class, $entity->region);
59+
self::assertSame($values['id'], $entity->id);
60+
self::assertSame($values['droplet_ids'], $entity->dropletIds);
61+
self::assertSame($values['name'], $entity->name);
62+
self::assertSame($values['description'], $entity->description);
63+
self::assertSame($values['size_gigabytes'], $entity->sizeGigabytes);
64+
self::assertSame($values['created_at'], $entity->createdAt);
65+
self::assertSame($values['filesystem_type'], $entity->filesystemType);
66+
self::assertSame($values['filesystem_label'], $entity->filesystemLabel);
67+
self::assertSame($values['tags'], $entity->tags);
68+
}
69+
70+
public function testConstructorAcceptsNullDropletIds(): void
71+
{
72+
$entity = new Volume([
73+
'id' => '506f78a4-e098-11e5-ad9f-000f53306ae1',
74+
'region' => [
75+
'name' => 'New York 1',
76+
'slug' => 'nyc1',
77+
'available' => true,
78+
'features' => [],
79+
'sizes' => [],
80+
],
81+
'droplet_ids' => null,
82+
'name' => 'example',
83+
'description' => 'Block store for examples',
84+
'size_gigabytes' => 10,
85+
'created_at' => '2020-03-02T17:00:49Z',
86+
'filesystem_type' => 'ext4',
87+
'filesystem_label' => 'example',
88+
]);
89+
90+
self::assertSame([], $entity->dropletIds);
91+
}
92+
}

0 commit comments

Comments
 (0)