graphql-php/tests/Utils/AssertValidNameTest.php

45 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
2018-09-02 13:44:21 +03:00
declare(strict_types=1);
namespace GraphQL\Tests\Utils;
use GraphQL\Error\Error;
use GraphQL\Error\InvariantViolation;
use GraphQL\Utils\Utils;
2018-07-29 18:43:10 +03:00
use PHPUnit\Framework\TestCase;
2018-07-29 18:43:10 +03:00
class AssertValidNameTest extends TestCase
{
// Describe: assertValidName()
/**
* @see it('throws for use of leading double underscores')
*/
public function testThrowsForUseOfLeadingDoubleUnderscores() : void
{
2018-07-29 18:43:10 +03:00
$this->expectException(Error::class);
$this->expectExceptionMessage('"__bad" must not begin with "__", which is reserved by GraphQL introspection.');
Utils::assertValidName('__bad');
}
/**
* @see it('throws for non-strings')
*/
public function testThrowsForNonStrings() : void
{
2018-07-29 18:43:10 +03:00
$this->expectException(InvariantViolation::class);
$this->expectExceptionMessage('Expected string');
Utils::assertValidName([]);
}
/**
* @see it('throws for names with invalid characters')
*/
public function testThrowsForNamesWithInvalidCharacters() : void
{
2018-07-29 18:43:10 +03:00
$this->expectException(Error::class);
$this->expectExceptionMessage('Names must match');
Utils::assertValidName('>--()-->');
}
}