2018-02-15 21:29:14 +01:00
|
|
|
<?php
|
2018-09-02 12:44:21 +02:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-02-15 21:29:14 +01:00
|
|
|
namespace GraphQL\Tests\Utils;
|
|
|
|
|
|
|
|
use GraphQL\Language\Parser;
|
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
use GraphQL\Type\Definition\Type;
|
|
|
|
use GraphQL\Validator\DocumentValidator;
|
2018-07-29 17:43:10 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-02-15 21:29:14 +01:00
|
|
|
|
2018-07-29 17:43:10 +02:00
|
|
|
class IsValidLiteralValueTest extends TestCase
|
2018-02-15 21:29:14 +01:00
|
|
|
{
|
|
|
|
// DESCRIBE: isValidLiteralValue
|
|
|
|
/**
|
2018-08-31 10:55:14 +02:00
|
|
|
* @see it('Returns no errors for a valid value')
|
2018-02-15 21:29:14 +01:00
|
|
|
*/
|
2018-08-31 11:07:29 +02:00
|
|
|
public function testReturnsNoErrorsForAValidValue() : void
|
2018-02-15 21:29:14 +01:00
|
|
|
{
|
2018-09-19 17:12:09 +02:00
|
|
|
self::assertEquals(
|
2018-02-15 21:29:14 +01:00
|
|
|
[],
|
|
|
|
DocumentValidator::isValidLiteralValue(Type::int(), Parser::parseValue('123'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 10:55:14 +02:00
|
|
|
* @see it('Returns errors for an invalid value')
|
2018-02-15 21:29:14 +01:00
|
|
|
*/
|
2018-08-31 11:07:29 +02:00
|
|
|
public function testReturnsErrorsForForInvalidValue() : void
|
2018-02-15 21:29:14 +01:00
|
|
|
{
|
|
|
|
$errors = DocumentValidator::isValidLiteralValue(Type::int(), Parser::parseValue('"abc"'));
|
|
|
|
|
2018-09-19 17:12:09 +02:00
|
|
|
self::assertCount(1, $errors);
|
|
|
|
self::assertEquals('Expected type Int, found "abc".', $errors[0]->getMessage());
|
|
|
|
self::assertEquals([new SourceLocation(1, 1)], $errors[0]->getLocations());
|
|
|
|
self::assertEquals(null, $errors[0]->getPath());
|
2018-02-15 21:29:14 +01:00
|
|
|
}
|
|
|
|
}
|