From c479658f0bb953ded4b29ca573404a318f1e798f Mon Sep 17 00:00:00 2001 From: EoleDev Date: Wed, 9 Mar 2016 15:36:02 +0100 Subject: New Library --- .../unit/Common/Transport/HandlerStackTest.php | 15 +++ .../unit/Common/Transport/JsonSerializerTest.php | 85 ++++++++++++++++ .../tests/unit/Common/Transport/MiddlewareTest.php | 59 +++++++++++ .../Common/Transport/RequestSerializerTest.php | 112 +++++++++++++++++++++ .../tests/unit/Common/Transport/UtilsTest.php | 30 ++++++ 5 files changed, 301 insertions(+) create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Transport/HandlerStackTest.php create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Transport/JsonSerializerTest.php create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Transport/MiddlewareTest.php create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Transport/RequestSerializerTest.php create mode 100644 server/vendor/php-opencloud/common/tests/unit/Common/Transport/UtilsTest.php (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Transport') diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/HandlerStackTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/HandlerStackTest.php new file mode 100644 index 0000000..ec1cf85 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/HandlerStackTest.php @@ -0,0 +1,15 @@ +assertInstanceOf(HandlerStack::class, HandlerStack::create(new MockHandler())); + } +} diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/JsonSerializerTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/JsonSerializerTest.php new file mode 100644 index 0000000..9075594 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/JsonSerializerTest.php @@ -0,0 +1,85 @@ +serializer = new JsonSerializer(); + } + + public function test_it_embeds_params_according_to_path() + { + $param = $this->prophesize(Parameter::class); + $param->isArray()->shouldBeCalled()->willReturn(false); + $param->isObject()->shouldBeCalled()->willReturn(false); + $param->getName()->shouldBeCalled()->willReturn('username'); + $param->getPath()->shouldBeCalled()->willReturn('auth.passwordCredentials'); + + $userValue = 'fooBar'; + + $expected = [ + 'auth' => [ + 'passwordCredentials' => [ + 'username' => $userValue, + ], + ], + ]; + + $actual = $this->serializer->stockJson($param->reveal(), $userValue, []); + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_arrays() + { + $param = $this->prophesize(Parameter::class); + $param->isArray()->shouldBeCalled()->willReturn(true); + $param->getName()->shouldBeCalled()->willReturn('fooBar'); + $param->getPath()->shouldBeCalled()->willReturn(false); + + $itemSchema = $this->prophesize(Parameter::class); + $itemSchema->isArray()->shouldBeCalled()->willReturn(false); + $itemSchema->isObject()->shouldBeCalled()->willReturn(false); + $itemSchema->getName()->shouldBeCalled()->willReturn(null); + $itemSchema->getPath()->shouldBeCalled()->willReturn(null); + + $param->getItemSchema()->shouldBeCalled()->willReturn($itemSchema); + + $userValues = ['1', '2', '3']; + + $expected = ['fooBar' => $userValues]; + + $actual = $this->serializer->stockJson($param->reveal(), $userValues, []); + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_objects() + { + $prop = $this->prophesize(Parameter::class); + $prop->isArray()->shouldBeCalled()->willReturn(false); + $prop->isObject()->shouldBeCalled()->willReturn(false); + $prop->getName()->shouldBeCalled()->willReturn('foo'); + $prop->getPath()->shouldBeCalled()->willReturn(null); + + $param = $this->prophesize(Parameter::class); + $param->isArray()->shouldBeCalled()->willReturn(false); + $param->isObject()->shouldBeCalled()->willReturn(true); + $param->getName()->shouldBeCalled()->willReturn('topLevel'); + $param->getPath()->shouldBeCalled()->willReturn(false); + $param->getProperty('foo')->shouldBeCalled()->willReturn($prop); + + $expected = ['topLevel' => ['foo' => true]]; + + $json = $this->serializer->stockJson($param->reveal(), ['foo' => true], []); + + $this->assertEquals($expected, $json); + } +} diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/MiddlewareTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/MiddlewareTest.php new file mode 100644 index 0000000..c445783 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/MiddlewareTest.php @@ -0,0 +1,59 @@ +assertEquals('pending', $promise->getState()); + + $promise->wait(); + $this->assertEquals('rejected', $promise->getState()); + } + + public function test_responses_are_left_alone_when_status_under_400() + { + $middleware = Middleware::httpErrors(); + + $response = new Response(204); + $handler = new MockHandler([$response]); + $fn = $middleware($handler); + + $promise = $fn(new Request('GET', 'http://foo.com'), []); + + $promise->then(function ($val) use ($response) { + $this->assertEquals($val, $response); + }); + + $promise->wait(); + } + + public function test_auth_handler_is_returned() + { + $generator = function () {}; + + $middleware = Middleware::authHandler($generator); + + $handler = new MockHandler([new Response(204)]); + $fn = $middleware($handler); + + $this->assertInstanceOf(AuthHandler::class, $fn); + } +} diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/RequestSerializerTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/RequestSerializerTest.php new file mode 100644 index 0000000..cf06220 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/RequestSerializerTest.php @@ -0,0 +1,112 @@ +js = $this->prophesize(JsonSerializer::class); + + $this->rs = new RequestSerializer($this->js->reveal()); + } + + public function test_it_ignores_undefined_params() + { + $op = $this->prophesize(Operation::class); + $op->getParam('foo')->shouldBeCalled()->willReturn(null); + + $this->assertEquals(['headers' => []], $this->rs->serializeOptions($op->reveal(), ['foo' => 'bar'])); + } + + public function test_it_serializes_queries() + { + $sch = $this->prophesize(Parameter::class); + $sch->getName()->shouldBeCalled()->willReturn('fooAlias'); + $sch->getLocation()->shouldBeCalled()->willReturn('query'); + + $op = $this->prophesize(Operation::class); + $op->getParam('foo')->shouldBeCalled()->willReturn($sch); + + $actual = $this->rs->serializeOptions($op->reveal(), ['foo' => 'bar']); + $expected = ['query' => ['fooAlias' => 'bar'], 'headers' => []]; + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_headers() + { + $sch = $this->prophesize(Parameter::class); + $sch->getLocation()->shouldBeCalled()->willReturn('header'); + $sch->getName()->shouldBeCalled()->willReturn('fooAlias'); + $sch->getPrefixedName()->shouldBeCalled()->willReturn('prefix-fooAlias'); + + $op = $this->prophesize(Operation::class); + $op->getParam('foo')->shouldBeCalled()->willReturn($sch); + + $actual = $this->rs->serializeOptions($op->reveal(), ['foo' => 'bar']); + $expected = ['headers' => ['prefix-fooAlias' => 'bar']]; + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_metadata_headers() + { + $itemSch = $this->prophesize(Parameter::class); + $itemSch->getName()->shouldBeCalled()->willReturn('foo'); + $itemSch->getPrefixedName()->shouldBeCalled()->willReturn('prefix-foo'); + + $sch = $this->prophesize(Parameter::class); + $sch->getItemSchema()->shouldBeCalled()->willReturn($itemSch); + $sch->getLocation()->shouldBeCalled()->willReturn('header'); + $sch->getName()->shouldBeCalled()->willReturn('metadata'); + + $op = $this->prophesize(Operation::class); + $op->getParam('metadata')->shouldBeCalled()->willReturn($sch); + + $actual = $this->rs->serializeOptions($op->reveal(), ['metadata' => ['foo' => 'bar']]); + $expected = ['headers' => ['prefix-foo' => 'bar']]; + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_json() + { + $sch = $this->prophesize(Parameter::class); + $sch->getLocation()->shouldBeCalled()->willReturn('json'); + + $op = $this->prophesize(Operation::class); + $op->getParam('foo')->shouldBeCalled()->willReturn($sch); + $op->getJsonKey()->shouldBeCalled()->willReturn('jsonKey'); + + $this->js->stockJson($sch, 'bar', [])->shouldBeCalled()->willReturn(['foo' => 'bar']); + + $actual = $this->rs->serializeOptions($op->reveal(), ['foo' => 'bar']); + $expected = ['json' => ['jsonKey' => ['foo' => 'bar']], 'headers' => []]; + + $this->assertEquals($expected, $actual); + } + + public function test_it_serializes_raw_vals() + { + $sch = $this->prophesize(Parameter::class); + $sch->getLocation()->shouldBeCalled()->willReturn('raw'); + + $op = $this->prophesize(Operation::class); + $op->getParam('foo')->shouldBeCalled()->willReturn($sch); + + $actual = $this->rs->serializeOptions($op->reveal(), ['foo' => 'bar']); + $expected = ['body' => 'bar', 'headers' => []]; + + $this->assertEquals($expected, $actual); + } +} diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/UtilsTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/UtilsTest.php new file mode 100644 index 0000000..3103ad4 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Transport/UtilsTest.php @@ -0,0 +1,30 @@ +assertInstanceOf(Uri::class, $uri); + $this->assertEquals(uri_for('http://openstack.org/foo/bar/baz/1/2'), $uri); + } +} -- cgit v1.2.3