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

@ -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,11 +95,10 @@ class QueryExecutionTest extends ServerTestCase
'errors' => [
[
'message' => 'This is the exception we want',
'path' => ['fieldWithSafeException'],
'trace' => []
]
]
'trace' => [],
],
],
];
$result = $this->executeQuery($query)->toArray();
@ -108,7 +108,7 @@ class QueryExecutionTest extends ServerTestCase
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'],

View File

@ -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';
}
}

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';
}
}