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 (#275)
by Hugo
15:12
created

ExecutorTest::testEnabledDebugInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\Request;
4
5
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
6
use GraphQL\Executor\Promise\PromiseAdapter;
7
use GraphQL\Type\Definition\ObjectType;
8
use GraphQL\Type\Definition\Type;
9
use GraphQL\Type\Schema;
10
use Overblog\GraphQLBundle\Executor\Executor;
11
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\EventDispatcher\EventDispatcher;
14
15
class ExecutorTest extends TestCase
16
{
17
    /** @var RequestExecutor */
18
    private $executor;
19
20
    /** @var EventDispatcher|\PHPUnit_Framework_MockObject_MockObject */
21
    private $dispatcher;
22
23
    private $request = ['query' => 'query debug{ myField }', 'variables' => [], 'operationName' => null];
24
25
    public function setUp()
26
    {
27
        $this->dispatcher = $this->getMockBuilder(EventDispatcher::class)->setMethods(['dispatch'])->getMock();
28
        $this->dispatcher->expects($this->any())->method('dispatch')->willReturnArgument(1);
29
30
        $this->executor = $this->createRequestExecutor();
31
        $queryType = new ObjectType([
32
            'name' => 'Query',
33
            'fields' => [
34
                'myField' => [
35
                    'type' => Type::boolean(),
36
                    'resolve' => function () {
37
                        return false;
38
                    },
39
                ],
40
            ],
41
        ]);
42
        $this->executor->addSchema('global', new Schema(['query' => $queryType]));
43
    }
44
45
    /**
46
     * @expectedException \RuntimeException
47
     * @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult".
48
     */
49
    public function testInvalidExecutorReturnNotObject()
50
    {
51
        $this->executor->setExecutor($this->createExecutorExecuteMock(false));
0 ignored issues
show
Documentation introduced by
$this->createExecutorExecuteMock(false) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Overblog\GraphQLB...utor\ExecutorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        $this->executor->execute(null, $this->request);
53
    }
54
55
    /**
56
     * @expectedException \RuntimeException
57
     * @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult".
58
     */
59
    public function testInvalidExecutorReturnInvalidObject()
60
    {
61
        $this->executor->setExecutor($this->createExecutorExecuteMock(new \stdClass()));
0 ignored issues
show
Documentation introduced by
$this->createExecutorExecuteMock(new \stdClass()) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Overblog\GraphQLB...utor\ExecutorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        $this->executor->execute(null, $this->request);
63
    }
64
65
    /**
66
     * @expectedException \RuntimeException
67
     * @expectedExceptionMessage PromiseAdapter should be an object instantiating "Overblog\GraphQLBundle\Executor\Promise\PromiseAdapterInterface" or "GraphQL\Executor\Promise\PromiseAdapter" with a "wait" method.
68
     */
69
    public function testInvalidExecutorAdapterPromise()
70
    {
71
        $this->executor->setPromiseAdapter(new ReactPromiseAdapter());
72
        $this->executor->execute(null, $this->request);
73
    }
74
75
    /**
76
     * @expectedException \RuntimeException
77
     * @expectedExceptionMessage At least one schema should be declare.
78
     */
79
    public function testGetSchemaNoSchemaFound()
80
    {
81
        $this->createRequestExecutor()->getSchema('fake');
82
    }
83
84
    private function createExecutorExecuteMock($returnValue)
85
    {
86
        $mock = $this->getMockBuilder(Executor::class)
87
            ->setMethods(['execute'])
88
            ->getMock();
89
90
        $mock->method('execute')->will($this->returnValue($returnValue));
91
92
        return $mock;
93
    }
94
95
    private function createRequestExecutor()
96
    {
97
        /** @var PromiseAdapter|\PHPUnit_Framework_MockObject_MockObject $promiseAdapter */
98
        $promiseAdapter = $this->getMockBuilder(PromiseAdapter::class)
99
            ->setMethods(array_merge(['wait'], get_class_methods(PromiseAdapter::class)))
100
            ->getMock();
101
102
        return new RequestExecutor(new Executor(), $this->dispatcher, $promiseAdapter);
0 ignored issues
show
Bug introduced by
It seems like $promiseAdapter defined by $this->getMockBuilder(\G...er::class)))->getMock() on line 98 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Overblog\GraphQLBundle\R...Executor::__construct() does only seem to accept object<GraphQL\Executor\Promise\PromiseAdapter>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
103
    }
104
}
105