2016-04-25 16:50:03 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
2017-07-03 14:04:32 +03:00
|
|
|
class ValidationTest extends TestCase
|
2016-04-25 16:50:03 +03:00
|
|
|
{
|
|
|
|
// Validate: Supports full validation
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it validates queries
|
|
|
|
*/
|
|
|
|
public function testValidatesQueries()
|
|
|
|
{
|
|
|
|
$this->expectPassesCompleteValidation('
|
|
|
|
query {
|
|
|
|
catOrDog {
|
|
|
|
... on Cat {
|
|
|
|
furColor
|
|
|
|
}
|
|
|
|
... on Dog {
|
|
|
|
isHousetrained
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
2018-02-12 00:31:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @it detects bad scalar parse
|
|
|
|
*/
|
|
|
|
public function testDetectsBadScalarParse()
|
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-10-24 23:51:27 +03:00
|
|
|
'message' => "Field \"invalidArg\" argument \"arg\" requires type Invalid, found \"bad value\"; Invalid scalar is always invalid: bad value",
|
2018-02-12 00:31:04 +03:00
|
|
|
'locations' => [ ['line' => 3, 'column' => 25] ]
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->expectInvalid(
|
|
|
|
$this->getTestSchema(),
|
|
|
|
null,
|
|
|
|
$doc,
|
|
|
|
[$expectedError]
|
|
|
|
);
|
2017-08-18 16:48:27 +03:00
|
|
|
}
|
2018-02-12 00:31:04 +03:00
|
|
|
|
2017-07-12 22:38:31 +03:00
|
|
|
public function testPassesValidationWithEmptyRules()
|
|
|
|
{
|
|
|
|
$query = '{invalid}';
|
|
|
|
|
|
|
|
$expectedError = [
|
2018-02-15 19:19:53 +03:00
|
|
|
'message' => 'Cannot query field "invalid" on type "QueryRoot". Did you mean "invalidArg"?',
|
2017-07-12 22:38:31 +03:00
|
|
|
'locations' => [ ['line' => 1, 'column' => 2] ]
|
|
|
|
];
|
|
|
|
$this->expectFailsCompleteValidation($query, [$expectedError]);
|
2018-02-11 15:15:51 +03:00
|
|
|
$this->expectValid($this->getTestSchema(), [], $query);
|
2017-07-12 22:38:31 +03:00
|
|
|
}
|
2016-04-25 16:50:03 +03:00
|
|
|
}
|