From c4fe304efe403e1ec69bd58ba5e7d916a977b42f Mon Sep 17 00:00:00 2001 From: spawnia Date: Mon, 3 Sep 2018 21:43:02 +0200 Subject: [PATCH] Fix coding style --- src/Error/FormattedError.php | 2 +- tests/Server/QueryExecutionTest.php | 14 ++++++------ tests/Server/ServerTestCase.php | 35 ++++------------------------- tests/Server/Unsafe.php | 30 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 tests/Server/Unsafe.php diff --git a/src/Error/FormattedError.php b/src/Error/FormattedError.php index fcf0914..8ca886a 100644 --- a/src/Error/FormattedError.php +++ b/src/Error/FormattedError.php @@ -247,7 +247,7 @@ class FormattedError $isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe(); - if(($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe){ + if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) { if ($e->getPrevious()) { throw $e->getPrevious(); } diff --git a/tests/Server/QueryExecutionTest.php b/tests/Server/QueryExecutionTest.php index 334d5b9..5a76f46 100644 --- a/tests/Server/QueryExecutionTest.php +++ b/tests/Server/QueryExecutionTest.php @@ -19,6 +19,7 @@ use GraphQL\Validator\Rules\CustomValidationRule; use GraphQL\Validator\ValidationContext; use function count; use function sprintf; +use Unsafe; class QueryExecutionTest extends ServerTestCase { @@ -94,21 +95,20 @@ class QueryExecutionTest extends ServerTestCase 'errors' => [ [ 'message' => 'This is the exception we want', - 'path' => ['fieldWithSafeException'], - 'trace' => [] - ] - ] + 'trace' => [], + ], + ], ]; $result = $this->executeQuery($query)->toArray(); $this->assertArraySubset($expected, $result); } - + public function testRethrowUnsafeExceptions() : void { $this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS); - $this->expectException(UnsafeException::class); + $this->expectException(Unsafe::class); $this->executeQuery(' { @@ -487,7 +487,7 @@ class QueryExecutionTest extends ServerTestCase [ 'data' => [ 'f1' => 'f1', - 'fieldWithSafeException' => null + 'fieldWithSafeException' => null, ], 'errors' => [ ['message' => 'This is the exception we want'], diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 7c87258..90f6849 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace GraphQL\Tests\Server; use GraphQL\Deferred; -use GraphQL\Error\ClientAware; use GraphQL\Error\UserError; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\Type; @@ -15,6 +14,7 @@ use function trigger_error; use const E_USER_DEPRECATED; use const E_USER_NOTICE; use const E_USER_WARNING; +use Unsafe; abstract class ServerTestCase extends TestCase { @@ -46,13 +46,13 @@ abstract class ServerTestCase extends TestCase 'type' => Type::string(), 'resolve' => function() { throw new UserError('This is the exception we want'); - } + }, ], 'fieldWithUnsafeException' => [ 'type' => Type::string(), 'resolve' => function() { - throw new UnsafeException('This exception should not be shown to the user'); - } + throw new Unsafe('This exception should not be shown to the user'); + }, ], 'testContextAndRootValue' => [ 'type' => Type::string(), @@ -108,30 +108,3 @@ abstract class ServerTestCase extends TestCase return $schema; } } - -class UnsafeException extends \Exception implements ClientAware -{ - /** - * Returns true when exception message is safe to be displayed to a client. - * - * @api - * @return bool - */ - public function isClientSafe() - { - return false; - } - - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - * - * @api - * @return string - */ - public function getCategory() - { - return 'unsafe'; - } -} diff --git a/tests/Server/Unsafe.php b/tests/Server/Unsafe.php new file mode 100644 index 0000000..d33a908 --- /dev/null +++ b/tests/Server/Unsafe.php @@ -0,0 +1,30 @@ +