Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#277)
by Jérémiah
20:41
created

ResolverMapTest::validMapDataProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 0
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\Resolver;
4
5
use Overblog\GraphQLBundle\Resolver\ResolverMap;
6
use Overblog\GraphQLBundle\Resolver\UnresolvableException;
7
use PHPUnit\Framework\TestCase;
8
9
class ResolverMapTest extends TestCase
10
{
11
    /**
12
     * @param array|\ArrayAccess $map
13
     * @param string             $typeName
14
     * @param string             $fieldName
15
     * @param \Closure|null      $expectedResolver
16
     *
17
     * @dataProvider validMapDataProvider
18
     */
19
    public function testResolve($map, $typeName, $fieldName, $expectedResolver)
20
    {
21
        $resolverMap = $this->createResolverMapMock($map);
22
        $resolver = $resolverMap->resolve($typeName, $fieldName);
0 ignored issues
show
Bug introduced by
The method resolve does only exist in Overblog\GraphQLBundle\Resolver\ResolverMap, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
23
        $this->assertSame($expectedResolver, $resolver);
24
    }
25
26
    public function testMapMustBeOverride()
27
    {
28
        /** @var ResolverMap|\PHPUnit_Framework_MockObject_MockObject $resolverMap */
29
        $resolverMap = $this->getMockBuilder(ResolverMap::class)->setMethods(null)->getMock();
30
        $this->expectException(\LogicException::class);
31
        $this->expectExceptionMessage(sprintf(
32
            'You must override the %s::map() method.',
33
            get_class($resolverMap)
34
        ));
35
36
        $resolverMap->resolve('Foo', 'bar');
0 ignored issues
show
Bug introduced by
The method resolve does only exist in Overblog\GraphQLBundle\Resolver\ResolverMap, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
37
    }
38
39
    /**
40
     * @dataProvider invalidMapDataProvider
41
     *
42
     * @param mixed  $invalidMap
43
     * @param string $invalidType
44
     */
45
    public function testInvalidMap($invalidMap, $invalidType)
46
    {
47
        $resolverMap = $this->createResolverMapMock($invalidMap);
48
        $this->expectException(\RuntimeException::class);
49
        $this->expectExceptionMessage(sprintf(
50
            '%s::map() should return an array or an instance of \ArrayAccess and \Traversable but got "%s".',
51
            get_class($resolverMap),
52
            $invalidType
53
        ));
54
        $resolverMap->resolve('Foo', 'bar');
0 ignored issues
show
Bug introduced by
The method resolve does only exist in Overblog\GraphQLBundle\Resolver\ResolverMap, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
    }
56
57
    public function testUnresolvable()
58
    {
59
        $resolverMap = $this->createResolverMapMock([
60
            'Query' => [
61
                ResolverMap::RESOLVE_FIELD => function () {
62
                },
63
            ],
64
        ]);
65
        $this->expectException(UnresolvableException::class);
66
        $this->expectExceptionMessage('Field "Foo.bar" could not be resolved.');
67
        $resolverMap->resolve('Foo', 'bar');
0 ignored issues
show
Bug introduced by
The method resolve does only exist in Overblog\GraphQLBundle\Resolver\ResolverMap, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
68
    }
69
70
    public function invalidMapDataProvider()
71
    {
72
        return [
73
            [null, 'NULL'],
74
            [false, 'boolean'],
75
            [true, 'boolean'],
76
            ['baz', 'string'],
77
            [new \stdClass(), 'stdClass'],
78
        ];
79
    }
80
81
    public function validMapDataProvider()
82
    {
83
        $arrayMap = $this->map();
84
        $objectMap = new \ArrayObject($arrayMap);
85
86
        $validMap = [];
87
88
        foreach ([$arrayMap, $objectMap] as $map) {
89
            $validMap = array_merge($validMap, [
90
                [$map, 'Query', ResolverMap::RESOLVE_FIELD, $map['Query'][ResolverMap::RESOLVE_FIELD]],
91
                [$map, 'Query', 'foo', $map['Query']['foo']],
92
                [$map, 'Query', 'bar', $map['Query']['bar']],
93
                [$map, 'Query', 'baz', null],
94
                [$map, 'FooInterface', ResolverMap::RESOLVE_TYPE, $map['FooInterface'][ResolverMap::RESOLVE_TYPE]],
95
            ]);
96
        }
97
98
        return $validMap;
99
    }
100
101
    /**
102
     * @param mixed $map
103
     *
104
     * @return ResolverMap|\PHPUnit_Framework_MockObject_MockObject
105
     */
106 View Code Duplication
    private function createResolverMapMock($map)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        /** @var ResolverMap|\PHPUnit_Framework_MockObject_MockObject $resolverMap */
109
        $resolverMap = $this->getMockBuilder(ResolverMap::class)->setMethods(['map'])->getMock();
110
        $resolverMap->method('map')->willReturn($map);
111
112
        return $resolverMap;
113
    }
114
115
    private function map()
116
    {
117
        return [
118
            'Query' => [
119
                ResolverMap::RESOLVE_FIELD => function () {
120
                },
121
                'foo' => function () {
122
                },
123
                'bar' => function () {
124
                },
125
                'baz' => null,
126
            ],
127
            'FooInterface' => [
128
                ResolverMap::RESOLVE_TYPE => function () {
129
                },
130
            ],
131
        ];
132
    }
133
}
134