diff options
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Transport')
5 files changed, 0 insertions, 301 deletions
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 deleted file mode 100644 index ec1cf85..0000000 --- a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/HandlerStackTest.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -namespace OpenCloud\Test\Common\Transport; - -use GuzzleHttp\Handler\MockHandler; -use OpenCloud\Common\Transport\HandlerStack; -use OpenCloud\Test\TestCase; - -class HandlerStackTest extends TestCase -{ - public function test_it_is_created() - { - $this->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 deleted file mode 100644 index 5e21833..0000000 --- a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/JsonSerializerTest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -namespace OpenCloud\Test\Common\Transport; - -use OpenCloud\Common\Api\Parameter; -use OpenCloud\Common\Transport\JsonSerializer; - -class JsonSerializerTest extends \PHPUnit_Framework_TestCase -{ - private $serializer; - - public function setUp() - { - $this->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(''); - $itemSchema->getPath()->shouldBeCalled()->willReturn(''); - - $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(''); - - $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(), (object) ['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 deleted file mode 100644 index c445783..0000000 --- a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/MiddlewareTest.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -namespace unit\Common\Transport; - -use GuzzleHttp\Handler\MockHandler; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; -use OpenCloud\Common\Transport\Middleware; -use OpenCloud\Test\TestCase; -use OpenCloud\Common\Auth\AuthHandler; - -class MiddlewareTest extends TestCase -{ - /** - * @expectedException \OpenCloud\Common\Error\BadResponseError - */ - public function test_exception_is_thrown_for_4xx_statuses() - { - $middleware = Middleware::httpErrors(); - - $handler = new MockHandler([new Response(404)]); - $fn = $middleware($handler); - - $promise = $fn(new Request('GET', 'http://foo.com'), []); - $this->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 deleted file mode 100644 index cf06220..0000000 --- a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/RequestSerializerTest.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php - -namespace OpenCloud\Test\Common\Transport; - -use OpenCloud\Common\Api\Operation; -use OpenCloud\Common\Api\Parameter; -use OpenCloud\Common\Transport\JsonSerializer; -use OpenCloud\Common\Transport\RequestSerializer; -use OpenCloud\Test\TestCase; - -class RequestSerializerTest extends TestCase -{ - private $rs; - private $js; - - public function setUp() - { - $this->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 deleted file mode 100644 index 3103ad4..0000000 --- a/server/vendor/php-opencloud/common/tests/unit/Common/Transport/UtilsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -namespace OpenCloud\Test\Common\Transport; - -use GuzzleHttp\Psr7\Response; -use function GuzzleHttp\Psr7\uri_for; -use GuzzleHttp\Psr7\Uri; -use OpenCloud\Common\Transport\Utils; -use OpenCloud\Test\TestCase; - -class UtilsTest extends TestCase -{ - /** - * @expectedException \InvalidArgumentException - */ - public function test_decoding_malformed_json_throws_error() - { - $response = new Response(200, [], \GuzzleHttp\Psr7\stream_for('{')); - - Utils::jsonDecode($response); - } - - public function test_it_adds_paths() - { - $uri = Utils::addPaths(uri_for('http://openstack.org/foo'), 'bar', 'baz', '1', '2'); - - $this->assertInstanceOf(Uri::class, $uri); - $this->assertEquals(uri_for('http://openstack.org/foo/bar/baz/1/2'), $uri); - } -} |
