Skip to content

Commit 01e5261

Browse files
author
Jamie Hannaford
authored
Merge pull request #140 from php-opencloud/improve-unit-tests
[rtr] Bump up unit tests code coverage
2 parents 2fca41c + d4288c4 commit 01e5261

File tree

5 files changed

+109
-4
lines changed

5 files changed

+109
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
4+
{
5+
"quota_set": {
6+
"gigabytes": 1,
7+
"snapshots": 2,
8+
"volumes": 3
9+
}
10+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace OpenStack\Test\BlockStorage\v2\Models;
4+
5+
use GuzzleHttp\Psr7\Response;
6+
use OpenStack\BlockStorage\v2\Api;
7+
use OpenStack\BlockStorage\v2\Models\QuotaSet;
8+
use OpenStack\Test\TestCase;
9+
10+
class QuotaSetTest extends TestCase
11+
{
12+
/** @var QuotaSet */
13+
private $quotaSet;
14+
15+
public function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->rootFixturesDir = dirname(__DIR__);
20+
21+
$this->quotaSet = new QuotaSet($this->client->reveal(), new Api());
22+
$this->quotaSet->tenantId = 'tenant-foo';
23+
}
24+
25+
public function test_it_retrieves()
26+
{
27+
$this->setupMock('GET', 'os-quota-sets/tenant-foo', [], [], 'GET_quota_set');
28+
29+
$this->quotaSet->retrieve();
30+
$this->assertEquals(1, $this->quotaSet->gigabytes);
31+
$this->assertEquals(2, $this->quotaSet->snapshots);
32+
$this->assertEquals(3, $this->quotaSet->volumes);
33+
}
34+
35+
public function test_it_updates()
36+
{
37+
$expectedJson = [
38+
'quota_set' => [
39+
'snapshots' => 2222,
40+
'volumes' => 1111,
41+
],
42+
];
43+
44+
$this->setupMock('PUT', 'os-quota-sets/tenant-foo', $expectedJson, [], 'GET_type');
45+
46+
$this->quotaSet->volumes = 1111;
47+
$this->quotaSet->snapshots = 2222;
48+
$this->quotaSet->update();
49+
}
50+
51+
public function test_it_deletes()
52+
{
53+
$this->setupMock('DELETE', 'os-quota-sets/tenant-foo', null, [], new Response(204));
54+
55+
$this->quotaSet->delete();
56+
}
57+
}

tests/unit/BlockStorage/v2/ServiceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Psr7\Response;
66
use OpenStack\BlockStorage\v2\Api;
7+
use OpenStack\BlockStorage\v2\Models\QuotaSet;
78
use OpenStack\BlockStorage\v2\Models\Snapshot;
89
use OpenStack\BlockStorage\v2\Models\Volume;
910
use OpenStack\BlockStorage\v2\Models\VolumeType;
@@ -179,4 +180,19 @@ public function test_it_gets_a_snapshot()
179180
$this->assertInstanceOf(Snapshot::class, $snapshot);
180181
$this->assertEquals('snapshotId', $snapshot->id);
181182
}
183+
184+
public function test_it_gets_quota_set()
185+
{
186+
$this->client
187+
->request('GET', 'os-quota-sets/tenant-id-1234', ['headers' => []])
188+
->shouldBeCalled()
189+
->willReturn($this->getFixture('GET_quota_set'));
190+
191+
$quotaSet = $this->service->getQuotaSet('tenant-id-1234');
192+
193+
$this->assertInstanceOf(QuotaSet::class, $quotaSet);
194+
$this->assertEquals(1, $quotaSet->gigabytes);
195+
$this->assertEquals(2, $quotaSet->snapshots);
196+
$this->assertEquals(3, $quotaSet->volumes);
197+
}
182198
}

tests/unit/Compute/v2/Models/ServerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public function setUp()
2626
$this->server->id = 'serverId';
2727
}
2828

29-
/**
30-
* @expectedException \RuntimeException
31-
*/
3229
public function test_it_creates()
3330
{
3431
$opts = [
@@ -45,12 +42,36 @@ public function test_it_creates()
4542

4643
$this->setupMock('POST', 'servers', $expectedJson, [], 'server-post');
4744
$this->assertInstanceOf(Server::class, $this->server->create($opts));
45+
}
4846

47+
public function test_it_creates_with_boot_from_volume()
48+
{
4949
$opts = [
5050
'name' => 'foo',
5151
'flavorId' => 'baz',
52+
'blockDeviceMapping' => [['uuid' => 'aaaa-ddddd-bbbb-ccccc']]
5253
];
53-
$this->server->create($opts);
54+
55+
$expectedJson = ['server' => [
56+
'name' => $opts['name'],
57+
'flavorRef' => $opts['flavorId'],
58+
'block_device_mapping_v2' => $opts['blockDeviceMapping']
59+
]];
60+
61+
$this->setupMock('POST', 'servers', $expectedJson, [], 'server-post');
62+
$this->assertInstanceOf(Server::class, $this->server->create($opts));
63+
}
64+
65+
/**
66+
* @expectedException \RuntimeException
67+
* @expectedExceptionMessage imageId or blockDeviceMapping.uuid must be set.
68+
*/
69+
public function test_it_requires_image_id_or_volume_id_to_create_servers()
70+
{
71+
$this->server->create([
72+
'name' => 'some-server-name',
73+
'flavorId' => 'apple'
74+
]);
5475
}
5576

5677
public function test_it_updates()

tests/unit/Compute/v2/ServiceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class ServiceTest extends TestCase
2020
{
21+
/** @var Service */
2122
private $service;
2223

2324
public function setUp()

0 commit comments

Comments
 (0)