Skip to content

Commit 8af2454

Browse files
Merge branch '4.6' into 4.7
2 parents 2da60f1 + 59b186d commit 8af2454

File tree

4 files changed

+170
-6
lines changed

4 files changed

+170
-6
lines changed

src/Entity/Account.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,31 @@ final class Account extends AbstractEntity
5454
* @var string
5555
*/
5656
public $statusMessage;
57+
58+
/**
59+
* @var Team
60+
*/
61+
public $team;
62+
63+
/**
64+
* @param array $parameters
65+
*
66+
* @return void
67+
*/
68+
public function build(array $parameters): void
69+
{
70+
foreach ($parameters as $property => $value) {
71+
switch ($property) {
72+
case 'team':
73+
if (\is_object($value)) {
74+
$this->team = new Team($value);
75+
}
76+
unset($parameters[$property]);
77+
78+
break;
79+
}
80+
}
81+
82+
parent::build($parameters);
83+
}
5784
}

src/Entity/Droplet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ final class Droplet extends AbstractEntity
140140
*/
141141
public $nextBackupWindow;
142142

143+
/**
144+
* @var string
145+
*/
146+
public $vpcUuid;
147+
143148
/**
144149
* @param array $parameters
145150
*

src/Entity/Team.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 <[email protected]>
9+
* (c) Graham Campbell <[email protected]>
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\Entity;
16+
17+
/**
18+
* @author Roy de Jong <[email protected]>
19+
*/
20+
final class Team extends AbstractEntity
21+
{
22+
/**
23+
* @var string
24+
*/
25+
public $uuid;
26+
27+
/**
28+
* @var string
29+
*/
30+
public $name;
31+
}

tests/DropletEntityTest.php

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
use DigitalOceanV2\Entity\AbstractEntity;
1818
use DigitalOceanV2\Entity\Droplet;
19+
use DigitalOceanV2\Entity\Image;
20+
use DigitalOceanV2\Entity\Region;
21+
use DigitalOceanV2\Entity\Size;
1922
use PHPUnit\Framework\TestCase;
2023

2124
/**
@@ -25,14 +28,112 @@ class DropletEntityTest extends TestCase
2528
{
2629
public function testConstructor(): void
2730
{
28-
$droplet = new Droplet([
29-
'id' => 123,
30-
'name' => 'Dave',
31-
]);
31+
$values = [
32+
'id' => 3164444,
33+
'name' => 'example.com',
34+
'memory' => 1024,
35+
'vcpus' => 1,
36+
'disk' => 25,
37+
'locked' => false,
38+
'status' => 'active',
39+
'kernel' => null,
40+
'created_at' => '2020-07-21T18:37:44Z',
41+
'features' => [
42+
'backups',
43+
'private_networking',
44+
'ipv6',
45+
],
46+
'backup_ids' => [
47+
53893572,
48+
],
49+
'next_backup_window' => [
50+
'start' => '2020-07-30T00:00:00Z',
51+
'end' => '2020-07-30T23:00:00Z',
52+
],
53+
'snapshot_ids' => [
54+
67512819,
55+
],
56+
'image' => (object) [
57+
'id' => 63663980,
58+
'name' => '20.04 (LTS) x64',
59+
'distribution' => 'Ubuntu',
60+
'slug' => 'ubuntu-20-04-x64',
61+
'public' => true,
62+
'regions' => [
63+
'ams2',
64+
'ams3',
65+
'blr1',
66+
'fra1',
67+
'tor1',
68+
],
69+
'created_at' => '2020-05-15T05:47:50Z',
70+
'type' => 'snapshot',
71+
'min_disk_size' => 20,
72+
'size_gigabytes' => 2.36,
73+
'description' => '',
74+
'tags' => [],
75+
'status' => 'available',
76+
'error_message' => '',
77+
],
78+
'volume_ids' => [],
79+
'size' => (object) [
80+
'slug' => 's-1vcpu-1gb',
81+
'memory' => 1024,
82+
'vcpus' => 1,
83+
'disk' => 25,
84+
'transfer' => 1,
85+
'price_monthly' => 5,
86+
'price_hourly' => 0.00743999984115362,
87+
'regions' => [
88+
'ams2',
89+
'ams3',
90+
'blr1',
91+
'sgp1',
92+
'tor1',
93+
],
94+
'available' => true,
95+
'description' => 'Basic',
96+
],
97+
'size_slug' => 's-1vcpu-1gb',
98+
'region' => (object) [
99+
'name' => 'New York 3',
100+
'slug' => 'nyc3',
101+
'features' => [
102+
'private_networking',
103+
'backups',
104+
'ipv6',
105+
],
106+
'available' => true,
107+
'sizes' => [
108+
's-1vcpu-1gb',
109+
's-1vcpu-2gb',
110+
's-1vcpu-3gb',
111+
],
112+
],
113+
'tags' => [
114+
'web',
115+
'env:prod',
116+
],
117+
'vpc_uuid' => '760e09ef-dc84-11e8-981e-3cfdfeaae000',
118+
];
119+
$droplet = new Droplet($values);
32120

33121
self::assertInstanceOf(AbstractEntity::class, $droplet);
34122
self::assertInstanceOf(Droplet::class, $droplet);
35-
self::assertSame(123, $droplet->id);
36-
self::assertSame('Dave', $droplet->name);
123+
self::assertInstanceOf(Region::class, $droplet->region);
124+
self::assertInstanceOf(Size::class, $droplet->size);
125+
self::assertInstanceOf(Image::class, $droplet->image);
126+
self::assertSame($values['id'], $droplet->id);
127+
self::assertSame($values['name'], $droplet->name);
128+
self::assertSame($values['memory'], $droplet->memory);
129+
self::assertSame($values['vcpus'], $droplet->vcpus);
130+
self::assertSame($values['disk'], $droplet->disk);
131+
self::assertSame($values['size_slug'], $droplet->sizeSlug);
132+
self::assertSame($values['locked'], $droplet->locked);
133+
self::assertSame($values['status'], $droplet->status);
134+
self::assertSame($values['created_at'], $droplet->createdAt);
135+
self::assertSame($values['features'], $droplet->features);
136+
self::assertSame($values['tags'], $droplet->tags);
137+
self::assertSame($values['vpc_uuid'], $droplet->vpcUuid);
37138
}
38139
}

0 commit comments

Comments
 (0)