diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-15 16:17:39 +0100 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-15 16:17:39 +0100 |
| commit | 26d10bc0fa4befbac54453228ae1ce89021bdec2 (patch) | |
| tree | 029d7240ecf7416205e5f76cf9107a6b5bdf8ca3 /server/vendor/php-opencloud/common/tests/unit/Common/Service | |
| parent | 8ad216dedf017f3d6de047a25d08db3b98e16361 (diff) | |
| parent | 03ef74d0cfe675a6e18a91f039182ca1b248d8f5 (diff) | |
Merge branch 'develop' into loic
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Service')
| -rw-r--r-- | server/vendor/php-opencloud/common/tests/unit/Common/Service/BuilderTest.php | 164 |
1 files changed, 164 insertions, 0 deletions
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 @@ +<?php + +namespace OpenCloud\Test\Common\Service; + +use GuzzleHttp\ClientInterface; +use OpenCloud\Common\Service\Builder; +use OpenCloud\Identity\v2\Models\Token; +use OpenCloud\Identity\v2\Service as IdentityV2; +use OpenCloud\Identity\v3\Service as IdentityV3; +use OpenCloud\Compute\v2\Service as ComputeV2; +use OpenCloud\Test\Common\Auth\FakeToken; +use OpenCloud\Test\TestCase; +use Prophecy\Argument; + +class BuilderTest extends TestCase +{ + private $builder; + private $opts; + + public function setUp() + { + $this->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 |
