|
| 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