From c479658f0bb953ded4b29ca573404a318f1e798f Mon Sep 17 00:00:00 2001 From: EoleDev Date: Wed, 9 Mar 2016 15:36:02 +0100 Subject: New Library --- .../tests/unit/Common/Service/BuilderTest.php | 164 +++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Service/BuilderTest.php (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Service') diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Service/BuilderTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Service/BuilderTest.php new file mode 100644 index 0000000..09e9918 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Service/BuilderTest.php @@ -0,0 +1,164 @@ +builder = new Builder([]); + + $this->opts = [ + 'username' => '1', + 'password' => '2', + 'tenantId' => '3', + 'authUrl' => '4', + 'region' => '5', + 'catalogName' => '6', + 'catalogType' => '7', + ]; + } + + /** + * @expectedException \Exception + */ + public function test_it_throws_exception_if_username_is_missing() + { + $this->builder->createService('Compute', 2, []); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_password_is_missing() + { + $this->builder->createService('Compute', 2, ['username' => 1]); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_both_tenantId_and_tenantName_is_missing() + { + $this->builder->createService('Compute', 2, [ + 'username' => 1, 'password' => 2, 'authUrl' => 4, 'region' => 5, 'catalogName' => 6, 'catalogType' => 7, + ]); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_authUrl_is_missing() + { + $this->builder->createService('Compute', 2, ['username' => 1, 'password' => 2, 'tenantId' => 3]); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_region_is_missing() + { + $this->builder->createService('Compute', 2, [ + 'username' => 1, 'password' => 2, 'tenantId' => 3, 'authUrl' => 4, + ]); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_catalogName_is_missing() + { + $this->builder->createService('Compute', 2, [ + 'username' => 1, 'password' => 2, 'tenantId' => 3, 'authUrl' => 4, + ]); + } + + /** + * @expectedException \Throwable + */ + public function test_it_throws_exception_if_catalogType_is_missing() + { + $this->builder->createService('Compute', 2, [ + 'username' => 1, 'password' => 2, 'tenantId' => 3, 'authUrl' => 4, 'region' => 5, 'catalogName' => 6, + ]); + } + +// public function test_it_builds_services_with_custom_identity_service() +// { +// $this->rootFixturesDir = dirname(dirname(__DIR__)) . '/Identity/v2/'; +// +// $token = $this->prophesize(FakeToken::class)->reveal(); +// $service = $this->prophesize(IdentityService::class); +// $service->authenticate(Argument::type('array'))->shouldBeCalled()->willReturn([$token, '']); +// +// $this->opts += [ +// 'identityService' => $service->reveal(), +// 'catalogName' => 'nova', +// 'catalogType' => 'compute', +// 'region' => 'RegionOne', +// ]; +// +// $service = $this->builder->createService('Compute', 2, $this->opts); +// $this->assertInstanceOf(ComputeV2::class, $service); +// } + + private function setupHttpClient() + { + $this->rootFixturesDir = dirname(dirname(__DIR__)) . '/Identity/v3/'; + + $response = $this->getFixture('token-get'); + + $expectedJson = [ + 'auth' => [ + 'identity' => [ + 'methods' => ['password'], + 'password' => ['user' => ['id' => '0ca8f6', 'password' => 'secretsecret']] + ] + ] + ]; + + $httpClient = $this->prophesize(ClientInterface::class); + $httpClient->request('POST', 'tokens', ['json' => $expectedJson])->shouldBeCalled()->willReturn($response); + + return $httpClient; + } + + public function it_builds_services_with_default_identity() + { + $httpClient = $this->setupHttpClient(); + + $options = [ + 'httpClient' => $httpClient->reveal(), + 'catalogName' => 'nova', + 'catalogType' => 'compute', + 'region' => 'RegionOne', + 'user' => [ + 'id' => '0ca8f6', + 'password' => 'secretsecret', + ] + ]; + + $service = $this->builder->createService('Compute', 2, $options); + $this->assertInstanceOf(ComputeV2::class, $service); + } + +// public function test_it_does_not_authenticate_when_creating_identity_services() +// { +// $this->assertInstanceOf(IdentityV3::class, $this->builder->createService('Identity', 3, [ +// 'authUrl' => 'foo.com', +// ])); +// } +} \ No newline at end of file -- cgit v1.2.3