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

Completed
Pull Request — master (#240)
by Renato
21:21 queued 17:44
created

ReactPromiseAdapterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testWaitWithNotSupportedPromise() 0 5 1
A testWaitRejectedPromise() 0 5 1
B testWaitAsyncPromise() 0 24 1
A testSkipsConversionWhenPromiseIsAGraphQlOne() 0 12 1
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\Error;
4
5
use GraphQL\Executor\Promise\Promise;
6
use Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter;
7
use PHPUnit\Framework\TestCase;
8
use React\Promise\FulfilledPromise;
9
use Symfony\Component\Process\PhpProcess;
10
11
class ReactPromiseAdapterTest extends TestCase
12
{
13
    /** @var ReactPromiseAdapter */
14
    private $adapter;
15
16
    public function setUp()
17
    {
18
        $this->adapter = new ReactPromiseAdapter();
19
    }
20
21
    /**
22
     * @expectedException \InvalidArgumentException
23
     * @expectedExceptionMessage The "Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter::wait" method must be call with compatible a Promise.
24
     */
25
    public function testWaitWithNotSupportedPromise()
26
    {
27
        $noSupportedPromise = new Promise(new \stdClass(), $this->adapter);
28
        $this->adapter->wait($noSupportedPromise);
29
    }
30
31
    /**
32
     * @expectedException \Exception
33
     * @expectedExceptionMessage Promise has been rejected!
34
     */
35
    public function testWaitRejectedPromise()
36
    {
37
        $rejected = $this->adapter->createRejected(new \Exception('Promise has been rejected!'));
0 ignored issues
show
Documentation introduced by
new \Exception('Promise has been rejected!') is of type object<Exception>, but the function expects a object<Throwable>.

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...
38
        $this->adapter->wait($rejected);
39
    }
40
41
    public function testWaitAsyncPromise()
42
    {
43
        $output = 'OK!';
44
        $process = new PhpProcess(<<<EOF
45
<?php
46
usleep(30);
47
echo '$output';
48
EOF
49
        );
50
51
        $promise = $this->adapter->create(function (callable $resolve) use (&$process) {
52
            $process->start(function () use ($resolve, &$process) {
53
                $output = $process->getOutput();
54
                $resolve($output);
55
            });
56
        });
57
58
        $this->assertEquals(
59
            $output,
60
            $this->adapter->wait($promise, function () use (&$process) {
61
                $process->wait();
62
            })
63
        );
64
    }
65
66
    public function testSkipsConversionWhenPromiseIsAGraphQlOne()
67
    {
68
        $reactAdapter = new ReactPromiseAdapter();
69
        $reactPromise = new FulfilledPromise(1);
70
71
        $promise = $reactAdapter->convertThenable($reactPromise);
72
        // Test it's already converted then skip it
73
        $reactAdapter->convertThenable($promise);
74
75
        $this->assertInstanceOf(Promise::class, $promise);
76
        $this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise);
77
    }
78
}
79