Fix coding style

This commit is contained in:
spawnia 2018-09-03 21:43:02 +02:00
parent e7513e356a
commit c4fe304efe
4 changed files with 42 additions and 39 deletions

View File

@ -247,7 +247,7 @@ class FormattedError
$isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe(); $isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe();
if(($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe){ if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) {
if ($e->getPrevious()) { if ($e->getPrevious()) {
throw $e->getPrevious(); throw $e->getPrevious();
} }

View File

@ -19,6 +19,7 @@ use GraphQL\Validator\Rules\CustomValidationRule;
use GraphQL\Validator\ValidationContext; use GraphQL\Validator\ValidationContext;
use function count; use function count;
use function sprintf; use function sprintf;
use Unsafe;
class QueryExecutionTest extends ServerTestCase class QueryExecutionTest extends ServerTestCase
{ {
@ -94,11 +95,10 @@ class QueryExecutionTest extends ServerTestCase
'errors' => [ 'errors' => [
[ [
'message' => 'This is the exception we want', 'message' => 'This is the exception we want',
'path' => ['fieldWithSafeException'], 'path' => ['fieldWithSafeException'],
'trace' => [] 'trace' => [],
] ],
] ],
]; ];
$result = $this->executeQuery($query)->toArray(); $result = $this->executeQuery($query)->toArray();
@ -108,7 +108,7 @@ class QueryExecutionTest extends ServerTestCase
public function testRethrowUnsafeExceptions() : void public function testRethrowUnsafeExceptions() : void
{ {
$this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS); $this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS);
$this->expectException(UnsafeException::class); $this->expectException(Unsafe::class);
$this->executeQuery(' $this->executeQuery('
{ {
@ -487,7 +487,7 @@ class QueryExecutionTest extends ServerTestCase
[ [
'data' => [ 'data' => [
'f1' => 'f1', 'f1' => 'f1',
'fieldWithSafeException' => null 'fieldWithSafeException' => null,
], ],
'errors' => [ 'errors' => [
['message' => 'This is the exception we want'], ['message' => 'This is the exception we want'],

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace GraphQL\Tests\Server; namespace GraphQL\Tests\Server;
use GraphQL\Deferred; use GraphQL\Deferred;
use GraphQL\Error\ClientAware;
use GraphQL\Error\UserError; use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type; use GraphQL\Type\Definition\Type;
@ -15,6 +14,7 @@ use function trigger_error;
use const E_USER_DEPRECATED; use const E_USER_DEPRECATED;
use const E_USER_NOTICE; use const E_USER_NOTICE;
use const E_USER_WARNING; use const E_USER_WARNING;
use Unsafe;
abstract class ServerTestCase extends TestCase abstract class ServerTestCase extends TestCase
{ {
@ -46,13 +46,13 @@ abstract class ServerTestCase extends TestCase
'type' => Type::string(), 'type' => Type::string(),
'resolve' => function() { 'resolve' => function() {
throw new UserError('This is the exception we want'); throw new UserError('This is the exception we want');
} },
], ],
'fieldWithUnsafeException' => [ 'fieldWithUnsafeException' => [
'type' => Type::string(), 'type' => Type::string(),
'resolve' => function() { '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' => [ 'testContextAndRootValue' => [
'type' => Type::string(), 'type' => Type::string(),
@ -108,30 +108,3 @@ abstract class ServerTestCase extends TestCase
return $schema; 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';
}
}

30
tests/Server/Unsafe.php Normal file
View File

@ -0,0 +1,30 @@
<?php
use GraphQL\Error\ClientAware;
class Unsafe 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';
}
}