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