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
22:38 queued 19:05
created

GraphQLParserTest::testParse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\Config\Parser;
4
5
use Overblog\GraphQLBundle\Config\Parser\GraphQLParser;
6
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
9
10
class GraphQLParserTest extends TestCase
11
{
12
    /** @var ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject */
13
    private $containerBuilder;
14
15
    public function setUp()
16
    {
17
        $this->containerBuilder = $this->getMockBuilder(ContainerBuilder::class)->setMethods(['addResource'])->getMock();
18
    }
19
20
    public function testParse()
21
    {
22
        $fileName = __DIR__.'/fixtures/graphql/schema.graphql';
23
        $expected = include __DIR__.'/fixtures/graphql/schema.php';
24
25
        $this->assertContainerAddFileToResources($fileName);
26
        $config = GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder);
27
        $this->assertEquals($expected, $config);
28
    }
29
30
    public function testParseEmptyFile()
31
    {
32
        $fileName = __DIR__.'/fixtures/graphql/empty.graphql';
33
34
        $this->assertContainerAddFileToResources($fileName);
35
36
        $config = GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder);
37
        $this->assertEquals([], $config);
38
    }
39
40
    public function testParseInvalidFile()
41
    {
42
        $fileName = __DIR__.'/fixtures/graphql/invalid.graphql';
43
        $this->expectException(InvalidArgumentException::class);
44
        $this->expectExceptionMessage(sprintf('An error occurred while parsing the file "%s"', $fileName));
45
        GraphQLParser::parse(new \SplFileInfo($fileName), $this->containerBuilder);
46
    }
47
48
    public function testParseNotSupportedSchemaDefinition()
49
    {
50
        $this->expectException(InvalidArgumentException::class);
51
        $this->expectExceptionMessage('Schema definition is not supported right now.');
52
        GraphQLParser::parse(new \SplFileInfo(__DIR__.'/fixtures/graphql/not-supported-schema-definition.graphql'), $this->containerBuilder);
53
    }
54
55
    public function testCustomScalarTypeDefaultFieldValue()
56
    {
57
        $this->expectException(\Exception::class);
58
        $this->expectExceptionMessage('Config entry must be override with ResolverMap to be used.');
59
        GraphQLParser::mustOverrideConfig();
60
    }
61
62
    private function assertContainerAddFileToResources($fileName)
63
    {
64
        $this->containerBuilder->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Depend...ection\ContainerBuilder.

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...
65
            ->method('addResource')
66
            ->with($fileName);
67
    }
68
}
69