mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Add test
This commit is contained in:
parent
25e341e9d9
commit
9e2c1dae87
23
tests/Type/ObjectIdStub.php
Normal file
23
tests/Type/ObjectIdStub.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace GraphQL\Tests\Type;
|
||||
|
||||
class ObjectIdStub
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->id;
|
||||
}
|
||||
}
|
@ -178,4 +178,25 @@ class ScalarSerializationTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// TODO: how should it behave on '0'?
|
||||
}
|
||||
|
||||
public function testSerializesOutputID()
|
||||
{
|
||||
$idType = Type::id();
|
||||
|
||||
$this->assertSame('string', $idType->serialize('string'));
|
||||
$this->assertSame('', $idType->serialize(''));
|
||||
$this->assertSame('1', $idType->serialize('1'));
|
||||
$this->assertSame('1', $idType->serialize(1));
|
||||
$this->assertSame('0', $idType->serialize(0));
|
||||
$this->assertSame('true', $idType->serialize(true));
|
||||
$this->assertSame('false', $idType->serialize(false));
|
||||
$this->assertSame('2', $idType->serialize(new ObjectIdStub(2)));
|
||||
|
||||
try {
|
||||
$idType->serialize(new \stdClass());
|
||||
$this->fail('Expected exception was not thrown');
|
||||
} catch (InvariantViolation $e) {
|
||||
$this->assertEquals('ID type cannot represent non scalar value: instance of stdClass', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user