TypeGeneratorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testNameAndFields() 0 9 1
A setUp() 0 5 1
A testextendAnnotatedObjectException() 0 11 1
A testMapAnnotatedObjectException() 0 6 1
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers;
4
5
use Mouf\Picotainer\Picotainer;
6
use stdClass;
7
use TheCodingMachine\GraphQL\Controllers\Fixtures\TypeFoo;
8
use TheCodingMachine\GraphQL\Controllers\Types\MutableObjectType;
9
10
class TypeGeneratorTest extends AbstractQueryProviderTest
11
{
12
    private $container;
13
14
    public function setUp()
15
    {
16
        $this->container = new Picotainer([
17
            TypeFoo::class => function() { return new TypeFoo(); },
18
            stdClass::class => function() { return new stdClass(); }
19
        ]);
20
    }
21
22
    public function testNameAndFields()
23
    {
24
        $typeGenerator = $this->getTypeGenerator();
25
26
        $type = $typeGenerator->mapAnnotatedObject(TypeFoo::class, $this->getTypeMapper(), $this->container);
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...r::mapAnnotatedObject() has too many arguments starting with $this->container. ( Ignorable by Annotation )

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

26
        /** @scrutinizer ignore-call */ 
27
        $type = $typeGenerator->mapAnnotatedObject(TypeFoo::class, $this->getTypeMapper(), $this->container);

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...
27
28
        $this->assertSame('TestObject', $type->name);
29
        $type->freeze();
30
        $this->assertCount(1, $type->getFields());
31
    }
32
33
    public function testMapAnnotatedObjectException()
34
    {
35
        $typeGenerator = $this->getTypeGenerator();
36
37
        $this->expectException(MissingAnnotationException::class);
38
        $typeGenerator->mapAnnotatedObject(stdClass::class, $this->getTypeMapper(), $this->container);
0 ignored issues
show
Unused Code introduced by
The call to TheCodingMachine\GraphQL...r::mapAnnotatedObject() has too many arguments starting with $this->container. ( Ignorable by Annotation )

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

38
        $typeGenerator->/** @scrutinizer ignore-call */ 
39
                        mapAnnotatedObject(stdClass::class, $this->getTypeMapper(), $this->container);

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...
39
    }
40
41
    public function testextendAnnotatedObjectException()
42
    {
43
        $typeGenerator = $this->getTypeGenerator();
44
45
        $type = new MutableObjectType([
46
            'name' => 'foo',
47
            'fields' => []
48
        ]);
49
50
        $this->expectException(MissingAnnotationException::class);
51
        $typeGenerator->extendAnnotatedObject(new stdClass(), $type, $this->getTypeMapper());
52
    }
53
}
54