Skip to content

Commit 677350e

Browse files
author
Jamie Hannaford
authored
Merge pull request #60 from haphan/unit-test
[rfr] Improve unit test coverage
2 parents 2185d14 + ba7d73c commit 677350e

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

tests/unit/OpenStackTest.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@
77
use OpenCloud\Common\Service\Builder;
88
use OpenStack\Identity\v3\Api;
99
use OpenStack\OpenStack;
10+
use OpenStack\Compute\v2\Service as ComputeServiceV2;
11+
use OpenStack\Identity\v2\Service as IdentityServiceV2;
12+
use OpenStack\Identity\v3\Service as IdentityServiceV3;
13+
use OpenStack\Networking\v2\Service as NetworkingServiceV2;
14+
use OpenStack\Networking\v2\Extensions\Layer3\Service as NetworkingServiceV2ExtLayer3;
15+
use OpenStack\Networking\v2\Extensions\SecurityGroups\Service as NetworkingServiceV2ExtSecGroup;
16+
use OpenStack\ObjectStore\v1\Service as ObjectStoreServiceV1;
17+
use OpenStack\BlockStorage\v2\Service as BlockStorageServiceV2;
18+
use OpenStack\Images\v2\Service as ImageServiceV2;
1019

1120
class OpenStackTest extends TestCase
1221
{
1322
private $builder;
23+
/** @var OpenStack */
1424
private $openstack;
1525

1626
public function setUp()
@@ -24,7 +34,7 @@ public function test_it_supports_compute_v2()
2434
$this->builder
2535
->createService('Compute\\v2', ['catalogName' => 'nova', 'catalogType' => 'compute'])
2636
->shouldBeCalled()
27-
->willReturn($this->service('Compute', 2));
37+
->willReturn($this->service(ComputeServiceV2::class));
2838

2939
$this->openstack->computeV2();
3040
}
@@ -34,7 +44,7 @@ public function test_it_supports_identity_v2()
3444
$this->builder
3545
->createService('Identity\\v2', ['catalogName' => 'keystone', 'catalogType' => 'identity'])
3646
->shouldBeCalled()
37-
->willReturn($this->service('Identity', 2));
47+
->willReturn($this->service(IdentityServiceV2::class));
3848

3949
$this->openstack->identityV2();
4050
}
@@ -44,7 +54,7 @@ public function test_it_supports_identity_v3()
4454
$this->builder
4555
->createService('Identity\\v3', ['catalogName' => 'keystone', 'catalogType' => 'identity'])
4656
->shouldBeCalled()
47-
->willReturn($this->service('Identity', 3));
57+
->willReturn($this->service(IdentityServiceV3::class));
4858

4959
$this->openstack->identityV3();
5060
}
@@ -54,17 +64,37 @@ public function test_it_supports_networking_v2()
5464
$this->builder
5565
->createService('Networking\\v2', ['catalogName' => 'neutron', 'catalogType' => 'network'])
5666
->shouldBeCalled()
57-
->willReturn($this->service('Networking', 2));
67+
->willReturn($this->service(NetworkingServiceV2::class));
5868

5969
$this->openstack->networkingV2();
6070
}
6171

72+
public function test_it_supports_networking_v2_ext_layer3()
73+
{
74+
$this->builder
75+
->createService('Networking\\v2\\Extensions\\Layer3', ['catalogName' => 'neutron', 'catalogType' => 'network'])
76+
->shouldBeCalled()
77+
->willReturn($this->service(NetworkingServiceV2ExtLayer3::class));
78+
79+
$this->openstack->networkingV2ExtLayer3();
80+
}
81+
82+
public function test_it_supports_networking_v2_ext_security_group()
83+
{
84+
$this->builder
85+
->createService('Networking\\v2\\Extensions\\SecurityGroups', ['catalogName' => 'neutron', 'catalogType' => 'network'])
86+
->shouldBeCalled()
87+
->willReturn($this->service(NetworkingServiceV2ExtSecGroup::class));
88+
89+
$this->openstack->networkingV2ExtSecGroups();
90+
}
91+
6292
public function test_it_supports_object_store_v1()
6393
{
6494
$this->builder
6595
->createService('ObjectStore\\v1', ['catalogName' => 'swift', 'catalogType' => 'object-store'])
6696
->shouldBeCalled()
67-
->willReturn($this->service('ObjectStore', 1));
97+
->willReturn($this->service(ObjectStoreServiceV1::class));
6898

6999
$this->openstack->objectStoreV1();
70100
}
@@ -74,7 +104,7 @@ public function test_it_supports_block_storage_v2()
74104
$this->builder
75105
->createService('BlockStorage\\v2', ['catalogName' => 'cinderv2', 'catalogType' => 'volumev2'])
76106
->shouldBeCalled()
77-
->willReturn($this->service('BlockStorage', 2));
107+
->willReturn($this->service(BlockStorageServiceV2::class));
78108

79109
$this->openstack->blockStorageV2();
80110
}
@@ -84,15 +114,13 @@ public function test_it_supports_images_v2()
84114
$this->builder
85115
->createService('Images\\v2', ['catalogName' => 'glance', 'catalogType' => 'image'])
86116
->shouldBeCalled()
87-
->willReturn($this->service('Images', 2));
117+
->willReturn($this->service(ImageServiceV2::class));
88118

89119
$this->openstack->imagesV2();
90120
}
91121

92-
private function service($service, $version)
122+
private function service($class)
93123
{
94-
$class = sprintf("OpenStack\\%s\\v%d\\Service", $service, $version);
95-
96124
return new $class($this->prophesize(ClientInterface::class)->reveal(), new Api());
97125
}
98126
}

0 commit comments

Comments
 (0)