diff options
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Error')
| -rw-r--r-- | server/vendor/php-opencloud/common/tests/unit/Common/Error/BadResponseErrorTest.php | 34 | ||||
| -rw-r--r-- | server/vendor/php-opencloud/common/tests/unit/Common/Error/BuilderTest.php | 117 |
2 files changed, 151 insertions, 0 deletions
diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Error/BadResponseErrorTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Error/BadResponseErrorTest.php new file mode 100644 index 0000000..7aa4bf1 --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Error/BadResponseErrorTest.php @@ -0,0 +1,34 @@ +<?php + +namespace OpenCloud\Test\Common\Error; + +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use OpenCloud\Common\Error\BadResponseError; +use OpenCloud\Test\TestCase; + +class BadResponseErrorTest extends TestCase +{ + private $e; + + public function setUp() + { + $this->e = new BadResponseError(); + } + + public function test_it_gets_request() + { + $r = new Request('GET', ''); + + $this->e->setRequest($r); + $this->assertEquals($this->e->getRequest(), $r); + } + + public function test_it_gets_response() + { + $r = new Response(500); + + $this->e->setResponse($r); + $this->assertEquals($this->e->getResponse(), $r); + } +} diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Error/BuilderTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Error/BuilderTest.php new file mode 100644 index 0000000..e23806d --- /dev/null +++ b/server/vendor/php-opencloud/common/tests/unit/Common/Error/BuilderTest.php @@ -0,0 +1,117 @@ +<?php + +namespace OpenCloud\Test\Common\Error; + +use function GuzzleHttp\Psr7\{stream_for,str}; + +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Psr7\{Request,Response}; +use OpenCloud\Common\Error\{BadResponseError,Builder,UserInputError}; + +class BuilderTest extends \PHPUnit_Framework_TestCase +{ + private $builder; + private $client; + + public function __construct() + { + $this->client = $this->prophesize(ClientInterface::class); + $this->builder = new Builder($this->client->reveal()); + } + + public function test_it_injects_client() + { + $this->assertInstanceOf(Builder::class, new Builder($this->client->reveal())); + } + + public function test_it_builds_http_errors() + { + $request = new Request('POST', '/servers'); + $response = new Response(400, [], stream_for('Invalid parameters')); + + $requestStr = trim($this->builder->str($request)); + $responseStr = trim($this->builder->str($response)); + + $errorMessage = <<<EOT +HTTP Error +~~~~~~~~~~ +The remote server returned a "400 Bad Request" error for the following transaction: + +Request +~~~~~~~ +$requestStr + +Response +~~~~~~~~ +$responseStr + +Further information +~~~~~~~~~~~~~~~~~~~ +Please ensure that your input values are valid and well-formed. Visit http://docs.php-opencloud.com/en/latest/http-codes for more information about debugging HTTP status codes, or file a support issue on https://github.com/php-opencloud/openstack/issues. +EOT; + + $e = new BadResponseError($errorMessage); + $e->setRequest($request); + $e->setResponse($response); + + $this->assertEquals($e, $this->builder->httpError($request, $response)); + } + + public function test_it_builds_user_input_errors() + { + $expected = 'A well-formed string'; + $value = ['foo' => true]; + $link = 'http://docs.php-opencloud.com/en/latest/index.html'; + + $errorMessage = <<<EOT +User Input Error +~~~~~~~~~~~~~~~~ +A well-formed string was expected, but the following value was passed in: + +Array +( + [foo] => 1 +) + +Please ensure that the value adheres to the expectation above. Visit $link for more information about input arguments. If you run into trouble, please open a support issue on https://github.com/php-opencloud/openstack/issues. +EOT; + + $this->client + ->request('HEAD', $link) + ->shouldBeCalled() + ->willReturn(new Response(200)); + + $e = new UserInputError($errorMessage); + + $this->assertEquals($e, $this->builder->userInputError($expected, $value, 'index.html')); + } + + public function test_dead_links_are_ignored() + { + $expected = 'A well-formed string'; + $value = ['foo' => true]; + + $errorMessage = <<<EOT +User Input Error +~~~~~~~~~~~~~~~~ +A well-formed string was expected, but the following value was passed in: + +Array +( + [foo] => 1 +) + +Please ensure that the value adheres to the expectation above. If you run into trouble, please open a support issue on https://github.com/php-opencloud/openstack/issues. +EOT; + + $this->client + ->request('HEAD', 'http://docs.php-opencloud.com/en/latest/sdffsda') + ->shouldBeCalled() + ->willThrow(ClientException::class); + + $e = new UserInputError($errorMessage); + + $this->assertEquals($e, $this->builder->userInputError($expected, $value, 'sdffsda')); + } +} |
