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 (#118)
by Jérémiah
05:21
created

ConnectionBuilderFromPromisedTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testReturnsAllElementsWithoutFilters() 0 6 1
A testRespectsASmallerFirst() 0 6 1
A testRespectsASmallerFirstWhenSlicing() 0 13 1
A promisedLetters() 0 4 2
A assertEqualsFromPromised() 0 4 1
A await() 0 19 2
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Tests\Relay\Connection\Output;
13
14
use Overblog\GraphQLBundle\Relay\Connection\Output\ConnectionBuilder;
15
use React\Promise\FulfilledPromise;
16
17
class ConnectionBuilderFromPromisedTest extends AbstractConnectionBuilderTest
18
{
19
    public function testReturnsAllElementsWithoutFilters()
20
    {
21
        $promise = ConnectionBuilder::connectionFromPromisedArray($this->promisedLetters(), []);
22
        $expected = $this->getExpectedConnection($this->letters, false, false);
23
        $this->assertEqualsFromPromised($expected, $promise);
24
    }
25
26
    public function testRespectsASmallerFirst()
27
    {
28
        $promise = ConnectionBuilder::connectionFromPromisedArray($this->promisedLetters(), ['first' => 2]);
29
        $expected = $this->getExpectedConnection(['A', 'B'], false, true);
30
        $this->assertEqualsFromPromised($expected, $promise);
31
    }
32
33
    public function testRespectsASmallerFirstWhenSlicing()
34
    {
35
        $promise = ConnectionBuilder::connectionFromPromisedArraySlice(
36
            $this->promisedLetters(['A', 'B', 'C']),
37
            ['first' => 2],
38
            [
39
                'sliceStart' => 0,
40
                'arrayLength' => 5,
41
            ]
42
        );
43
        $expected = $this->getExpectedConnection(['A', 'B'], false, true);
44
        $this->assertEqualsFromPromised($expected, $promise);
45
    }
46
47
    private function promisedLetters(array $letters = null)
48
    {
49
        return \React\Promise\resolve($letters ?: $this->letters);
50
    }
51
52
    private function assertEqualsFromPromised($expected, FulfilledPromise $promise)
53
    {
54
        $this->assertEquals($expected, self::await($promise));
55
    }
56
57
    private static function await(FulfilledPromise $promise)
58
    {
59
        $resolvedValue = null;
60
        $rejectedReason = null;
61
        $promise->then(
62
            function ($value) use (&$resolvedValue) {
63
                $resolvedValue = $value;
64
            },
65
            function ($reason) use (&$rejectedReason) {
66
                $rejectedReason = $reason;
67
            }
68
        );
69
70
        if ($rejectedReason instanceof \Exception) {
71
            throw $rejectedReason;
72
        }
73
74
        return $resolvedValue;
75
    }
76
}
77