graphql-php/tests/Validator/ValidationTest.php

63 lines
1.5 KiB
PHP
Raw Normal View History

2016-04-25 16:50:03 +03:00
<?php
namespace GraphQL\Tests\Validator;
2018-07-29 18:43:10 +03:00
class ValidationTest extends ValidatorTestCase
2016-04-25 16:50:03 +03:00
{
// Validate: Supports full validation
/**
* @see it('validates queries')
2016-04-25 16:50:03 +03:00
*/
public function testValidatesQueries()
{
$this->expectPassesCompleteValidation('
query {
catOrDog {
... on Cat {
furColor
}
... on Dog {
isHousetrained
}
}
}
');
}
/**
* @see it('detects bad scalar parse')
*/
public function testDetectsBadScalarParse()
{
$doc = '
query {
invalidArg(arg: "bad value")
}
';
$expectedError = [
'message' => "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);
}
2016-04-25 16:50:03 +03:00
}