2018-02-15 14:14:08 +03:00
|
|
|
<?php
|
|
|
|
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-02-15 14:14:08 +03:00
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class AssertValidNameTest extends TestCase
|
2018-02-15 14:14:08 +03:00
|
|
|
{
|
|
|
|
// Describe: assertValidName()
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('throws for use of leading double underscores')
|
2018-02-15 14:14:08 +03:00
|
|
|
*/
|
|
|
|
public function testThrowsForUseOfLeadingDoubleUnderscores()
|
|
|
|
{
|
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.');
|
2018-02-15 14:14:08 +03:00
|
|
|
Utils::assertValidName('__bad');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('throws for non-strings')
|
2018-02-15 14:14:08 +03:00
|
|
|
*/
|
|
|
|
public function testThrowsForNonStrings()
|
|
|
|
{
|
2018-07-29 18:43:10 +03:00
|
|
|
$this->expectException(InvariantViolation::class);
|
|
|
|
$this->expectExceptionMessage('Expected string');
|
2018-02-15 14:14:08 +03:00
|
|
|
Utils::assertValidName([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('throws for names with invalid characters')
|
2018-02-15 14:14:08 +03:00
|
|
|
*/
|
|
|
|
public function testThrowsForNamesWithInvalidCharacters()
|
|
|
|
{
|
2018-07-29 18:43:10 +03:00
|
|
|
$this->expectException(Error::class);
|
|
|
|
$this->expectExceptionMessage('Names must match');
|
2018-02-15 14:14:08 +03:00
|
|
|
Utils::assertValidName('>--()-->');
|
|
|
|
}
|
|
|
|
}
|