graphql-php/tests/Utils/IsValidLiteralValueTest.php

40 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2018-09-02 13:44:21 +03:00
declare(strict_types=1);
namespace GraphQL\Tests\Utils;
use GraphQL\Language\Parser;
use GraphQL\Language\SourceLocation;
use GraphQL\Type\Definition\Type;
use GraphQL\Validator\DocumentValidator;
2018-07-29 18:43:10 +03:00
use PHPUnit\Framework\TestCase;
2018-07-29 18:43:10 +03:00
class IsValidLiteralValueTest extends TestCase
{
// DESCRIBE: isValidLiteralValue
/**
* @see it('Returns no errors for a valid value')
*/
public function testReturnsNoErrorsForAValidValue() : void
{
$this->assertEquals(
[],
DocumentValidator::isValidLiteralValue(Type::int(), Parser::parseValue('123'))
);
}
/**
* @see it('Returns errors for an invalid value')
*/
public function testReturnsErrorsForForInvalidValue() : void
{
$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());
}
}