2016-04-25 16:50:03 +03:00
|
|
|
<?php
|
2018-09-02 14:08:49 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-04-25 16:50:03 +03:00
|
|
|
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
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('validates queries')
|
2016-04-25 16:50:03 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testValidatesQueries() : void
|
2016-04-25 16:50:03 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesCompleteValidation('
|
|
|
|
query {
|
|
|
|
catOrDog {
|
|
|
|
... on Cat {
|
|
|
|
furColor
|
|
|
|
}
|
|
|
|
... on Dog {
|
|
|
|
isHousetrained
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
2018-02-12 00:31:04 +03:00
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('detects bad scalar parse')
|
2018-02-12 00:31:04 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDetectsBadScalarParse() : void
|
2017-08-18 16:48:27 +03:00
|
|
|
{
|
2018-02-12 00:31:04 +03:00
|
|
|
$doc = '
|
|
|
|
query {
|
|
|
|
invalidArg(arg: "bad value")
|
|
|
|
}
|
|
|
|
';
|
2017-07-12 22:38:31 +03:00
|
|
|
|
2018-02-12 00:31:04 +03:00
|
|
|
$expectedError = [
|
2018-11-28 17:35:21 +03:00
|
|
|
'message' => 'Field "invalidArg" argument "arg" requires type Invalid, found "bad value"; Invalid scalar is always invalid: bad value',
|
2018-09-02 14:08:49 +03:00
|
|
|
'locations' => [['line' => 3, 'column' => 25]],
|
2018-02-12 00:31:04 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->expectInvalid(
|
2018-10-09 17:51:23 +03:00
|
|
|
self::getTestSchema(),
|
2018-02-12 00:31:04 +03:00
|
|
|
null,
|
|
|
|
$doc,
|
|
|
|
[$expectedError]
|
|
|
|
);
|
2017-08-18 16:48:27 +03:00
|
|
|
}
|
2018-02-12 00:31:04 +03:00
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testPassesValidationWithEmptyRules() : void
|
2017-07-12 22:38:31 +03:00
|
|
|
{
|
|
|
|
$query = '{invalid}';
|
|
|
|
|
|
|
|
$expectedError = [
|
2018-09-02 14:08:49 +03:00
|
|
|
'message' => 'Cannot query field "invalid" on type "QueryRoot". Did you mean "invalidArg"?',
|
|
|
|
'locations' => [['line' => 1, 'column' => 2]],
|
2017-07-12 22:38:31 +03:00
|
|
|
];
|
|
|
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
2018-10-09 17:51:23 +03:00
|
|
|
$this->expectValid(self::getTestSchema(), [], $query);
|
2017-07-12 22:38:31 +03:00
|
|
|
}
|
2016-04-25 16:50:03 +03:00
|
|
|
}
|