Completed
Push — master ( bcdd48...673801 )
by David
20:07
created

GlobTypeMapperTest::testGlobTypeMapperInputType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Mappers;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Mouf\Picotainer\Picotainer;
7
use Symfony\Component\Cache\Simple\NullCache;
8
use TheCodingMachine\GraphQL\Controllers\AbstractQueryProviderTest;
9
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject;
10
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestType;
11
use TheCodingMachine\GraphQL\Controllers\Fixtures\Types\FooType;
12
13
class GlobTypeMapperTest extends AbstractQueryProviderTest
14
{
15
    public function testGlobTypeMapper()
16
    {
17
        $container = new Picotainer([
18
            FooType::class => function() {
19
                return new FooType($this->getRegistry());
20
            }
21
        ]);
22
23
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\Types', $container, new AnnotationReader(), new NullCache());
24
25
        $this->assertTrue($mapper->canMapClassToType(TestObject::class));
26
        $this->assertInstanceOf(FooType::class, $mapper->mapClassToType(TestObject::class));
27
28
        $this->expectException(CannotMapTypeException::class);
29
        $mapper->mapClassToType(\stdClass::class);
30
    }
31
32
    public function testGlobTypeMapperException()
33
    {
34
        $container = new Picotainer([
35
            TestType::class => function() {
36
                return new TestType($this->getRegistry());
37
            }
38
        ]);
39
40
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures', $container, new AnnotationReader(), new NullCache());
41
42
        $this->expectException(DuplicateMappingException::class);
43
        $mapper->canMapClassToType(TestType::class);
44
    }
45
46
    public function testGlobTypeMapperInputType()
47
    {
48
        $container = new Picotainer([
49
            FooType::class => function() {
50
                return new FooType($this->getRegistry());
51
            }
52
        ]);
53
54
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\Types', $container, new AnnotationReader(), new NullCache());
55
56
        $this->assertFalse($mapper->canMapClassToInputType(TestObject::class));
57
58
        $this->expectException(CannotMapTypeException::class);
59
        $mapper->mapClassToInputType(TestType::class);
60
    }
61
}
62