Completed
Pull Request — master (#44)
by David
02:18
created

GlobTypeMapperTest::testGlobTypeMapperInputType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
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\Annotations\Exceptions\ClassNotFoundException;
10
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject;
11
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestType;
12
use TheCodingMachine\GraphQL\Controllers\Fixtures\Types\FooType;
13
use TheCodingMachine\GraphQL\Controllers\TypeGenerator;
14
use GraphQL\Type\Definition\ObjectType;
15
16
class GlobTypeMapperTest extends AbstractQueryProviderTest
17
{
18
    public function testGlobTypeMapper()
19
    {
20
        $container = new Picotainer([
21
            FooType::class => function() {
22
                return new FooType($this->getRegistry());
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...\FooType::__construct() has too many arguments starting with $this->getRegistry(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
                return /** @scrutinizer ignore-call */ new FooType($this->getRegistry());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
23
            }
24
        ]);
25
26
        $typeGenerator = new TypeGenerator($this->getRegistry());
27
28
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\Types', $typeGenerator, $container, new AnnotationReader(), new NullCache());
29
30
        $this->assertTrue($mapper->canMapClassToType(TestObject::class));
31
        $this->assertInstanceOf(ObjectType::class, $mapper->mapClassToType(TestObject::class));
32
        $this->assertSame([TestObject::class], $mapper->getSupportedClasses());
33
34
        $this->expectException(CannotMapTypeException::class);
35
        $mapper->mapClassToType(\stdClass::class);
36
    }
37
38
    public function testGlobTypeMapperException()
39
    {
40
        $container = new Picotainer([
41
            TestType::class => function() {
42
                return new TestType($this->getRegistry());
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...TestType::__construct() has too many arguments starting with $this->getRegistry(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
                return /** @scrutinizer ignore-call */ new TestType($this->getRegistry());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
43
            }
44
        ]);
45
46
        $typeGenerator = new TypeGenerator($this->getRegistry());
47
48
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\DuplicateTypes', $typeGenerator, $container, new AnnotationReader(), new NullCache());
49
50
        $this->expectException(DuplicateMappingException::class);
51
        $mapper->canMapClassToType(TestType::class);
52
    }
53
54
    public function testGlobTypeMapperClassNotFoundException()
55
    {
56
        $container = new Picotainer([
57
            TestType::class => function() {
58
                return new TestType($this->getRegistry());
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...TestType::__construct() has too many arguments starting with $this->getRegistry(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
                return /** @scrutinizer ignore-call */ new TestType($this->getRegistry());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
59
            }
60
        ]);
61
62
        $typeGenerator = new TypeGenerator($this->getRegistry());
63
64
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\BadClassType', $typeGenerator, $container, new AnnotationReader(), new NullCache());
65
66
        $this->expectException(ClassNotFoundException::class);
67
        $this->expectExceptionMessage("Could not autoload class 'Foobar' defined in @Type annotation of class 'TheCodingMachine\\GraphQL\\Controllers\\Fixtures\\BadClassType\\TestType'");
68
        $mapper->canMapClassToType(TestType::class);
69
    }
70
71
    public function testGlobTypeMapperInputType()
72
    {
73
        $container = new Picotainer([
74
            FooType::class => function() {
75
                return new FooType($this->getRegistry());
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...\FooType::__construct() has too many arguments starting with $this->getRegistry(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
                return /** @scrutinizer ignore-call */ new FooType($this->getRegistry());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
76
            }
77
        ]);
78
79
        $typeGenerator = new TypeGenerator($this->getRegistry());
80
81
        $mapper = new GlobTypeMapper('TheCodingMachine\GraphQL\Controllers\Fixtures\Types', $typeGenerator, $container, new AnnotationReader(), new NullCache());
82
83
        $this->assertFalse($mapper->canMapClassToInputType(TestObject::class));
84
85
        $this->expectException(CannotMapTypeException::class);
86
        $mapper->mapClassToInputType(TestType::class);
87
    }
88
}
89