Completed
Push — master ( ce838f...e81cc5 )
by Portey
37:21
created

ScalarTypeTest::testTypeName()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 3 Features 2
Metric Value
c 6
b 3
f 2
dl 0
loc 9
rs 9.2
cc 4
eloc 5
nc 3
nop 0
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 testScalarPrimitives()
19
    {
20
        foreach (TypeMap::getScalarTypes() as $typeName) {
21
            $className = 'Youshido\GraphQL\Type\Scalar\\' . (ucfirst($typeName) == 'Datetime' ? 'DateTime' : ucfirst($typeName)) . 'Type';
22
            /** @var TypeInterface $object */
23
            $object         = new $className();
24
            $testDataMethod = 'get' . $typeName . 'TestData';
25
            $this->checkDescription($object);
26
27
            foreach (call_user_func(['Youshido\Tests\DataProvider\TestScalarDataProvider', $testDataMethod]) as list($data, $serialized, $isValid)) {
28
29
                $this->checkSerialization($object, $data, $serialized);
30
31
                if ($isValid) {
32
                    $this->assertTrue($object->isValidValue($data), $typeName . ' validation for :' . serialize($data));
33
                } else {
34
                    $this->assertFalse($object->isValidValue($data), $typeName . ' validation for :' . serialize($data));
35
                }
36
            }
37
        }
38
    }
39
40
    private function checkDescription(TypeInterface $object)
41
    {
42
        $this->assertNotEmpty($object->getDescription());
43
    }
44
45
    private function checkSerialization(TypeInterface $object, $input, $expected)
46
    {
47
        $this->assertEquals($expected, $object->serialize($input), $object->getName() . ' serialize for: ' . serialize($input));
48
    }
49
50
}
51