1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is a part of graphql-youshido project. |
4
|
|
|
* |
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
6
|
|
|
* created: 11/27/15 1:11 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Youshido\Tests; |
10
|
|
|
|
11
|
|
|
use Youshido\GraphQL\Type\TypeInterface; |
12
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
13
|
|
|
use Youshido\Tests\DataProvider\TestScalarDataProvider; |
14
|
|
|
|
15
|
|
|
class ScalarTypeTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public function testTypeName() |
19
|
|
|
{ |
20
|
|
|
foreach (TypeMap::getScalarTypes() as $typeName) { |
21
|
|
|
$className = 'Youshido\GraphQL\Type\Scalar\\' . ucfirst($typeName) . 'Type'; |
22
|
|
|
/** @var TypeInterface $object */ |
23
|
|
|
$object = new $className(); |
24
|
|
|
$this->assertEquals(ucfirst($typeName) == 'Datetime' ? 'DateTime' : ucfirst($typeName), $object->getName()); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testScalarPrimitives() |
29
|
|
|
{ |
30
|
|
|
foreach (TypeMap::getScalarTypes() as $typeName) { |
31
|
|
|
$className = 'Youshido\GraphQL\Type\Scalar\\' . (ucfirst($typeName) == 'Datetime' ? 'DateTime' : ucfirst($typeName)) . 'Type'; |
32
|
|
|
/** @var TypeInterface $object */ |
33
|
|
|
$object = new $className(); |
34
|
|
|
$testDataMethod = 'get' . $typeName . 'TestData'; |
35
|
|
|
$this->checkDescription($object); |
36
|
|
|
|
37
|
|
|
foreach (call_user_func(['Youshido\Tests\DataProvider\TestScalarDataProvider', $testDataMethod]) as list($data, $serialized, $isValid)) { |
38
|
|
|
|
39
|
|
|
$this->checkSerialization($object, $data, $serialized); |
40
|
|
|
|
41
|
|
|
if ($isValid) { |
42
|
|
|
$this->assertTrue($object->isValidValue($data), $typeName . ' validation for :' . serialize($data)); |
43
|
|
|
} else { |
44
|
|
|
$this->assertFalse($object->isValidValue($data), $typeName . ' validation for :' . serialize($data)); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function checkDescription(TypeInterface $object) |
51
|
|
|
{ |
52
|
|
|
$this->assertNotEmpty($object->getDescription()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function checkSerialization(TypeInterface $object, $input, $expected) |
56
|
|
|
{ |
57
|
|
|
$this->assertEquals($expected, $object->serialize($input), $object->getName() . ' serialize for: ' . serialize($input)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|