graphql-php/tests/Validator/ValidationTest.php
Daniel Tschinder 17520876d8 Update some validators to latest upstream version
This includes:
graphql/graphql-js#1147
graphql/graphql-js#355

This also fixes two bugs in the Schema
 - types that were not found where still added to the typeMap
 - InputObject args should not be searched for types.
2018-02-15 17:19:53 +01:00

68 lines
1.6 KiB
PHP

<?php
namespace GraphQL\Tests\Validator;
use GraphQL\Error\FormattedError;
use GraphQL\Validator\DocumentValidator;
use GraphQL\Validator\Rules\QueryComplexity;
class ValidationTest extends TestCase
{
// Validate: Supports full validation
/**
* @it validates queries
*/
public function testValidatesQueries()
{
$this->expectPassesCompleteValidation('
query {
catOrDog {
... on Cat {
furColor
}
... on Dog {
isHousetrained
}
}
}
');
}
/**
* @it detects bad scalar parse
*/
public function testDetectsBadScalarParse()
{
$doc = '
query {
invalidArg(arg: "bad value")
}
';
$expectedError = [
'message' => "Argument \"arg\" has invalid value \"bad value\".
Expected type \"Invalid\", found \"bad value\"; Invalid scalar is always invalid: bad value",
'locations' => [ ['line' => 3, 'column' => 25] ]
];
$this->expectInvalid(
$this->getTestSchema(),
null,
$doc,
[$expectedError]
);
}
public function testPassesValidationWithEmptyRules()
{
$query = '{invalid}';
$expectedError = [
'message' => 'Cannot query field "invalid" on type "QueryRoot". Did you mean "invalidArg"?',
'locations' => [ ['line' => 1, 'column' => 2] ]
];
$this->expectFailsCompleteValidation($query, [$expectedError]);
$this->expectValid($this->getTestSchema(), [], $query);
}
}