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
Push — master ( 6d7704...02229b )
by Jérémiah
48s
created

testRespectsASmallerFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
    /**
34
     * @param $invalidPromise
35
     * @dataProvider invalidPromiseDataProvider
36
     *
37
     * @expectedException \InvalidArgumentException
38
     * @expectedExceptionMessage This is not a valid promise.
39
     */
40
    public function testInvalidPromise($invalidPromise)
41
    {
42
        ConnectionBuilder::connectionFromPromisedArray($invalidPromise, []);
43
    }
44
45
    public function invalidPromiseDataProvider()
46
    {
47
        return [
48
            [new \stdClass()],
49
            ['fake'],
50
            [['fake']],
51
            [false],
52
            [true],
53
        ];
54
    }
55
56
    public function testRespectsASmallerFirstWhenSlicing()
57
    {
58
        $promise = ConnectionBuilder::connectionFromPromisedArraySlice(
59
            $this->promisedLetters(['A', 'B', 'C']),
60
            ['first' => 2],
61
            [
62
                'sliceStart' => 0,
63
                'arrayLength' => 5,
64
            ]
65
        );
66
        $expected = $this->getExpectedConnection(['A', 'B'], false, true);
67
        $this->assertEqualsFromPromised($expected, $promise);
68
    }
69
70
    /**
71
     * @param $invalidPromise
72
     * @dataProvider invalidPromiseDataProvider
73
     *
74
     * @expectedException \InvalidArgumentException
75
     * @expectedExceptionMessage This is not a valid promise.
76
     */
77
    public function testInvalidPromiseWhenSlicing($invalidPromise)
78
    {
79
        ConnectionBuilder::connectionFromPromisedArraySlice($invalidPromise, [], []);
80
    }
81
82
    private function promisedLetters(array $letters = null)
83
    {
84
        return \React\Promise\resolve($letters ?: $this->letters);
85
    }
86
87
    private function assertEqualsFromPromised($expected, FulfilledPromise $promise)
88
    {
89
        $this->assertEquals($expected, self::await($promise));
90
    }
91
92
    private static function await(FulfilledPromise $promise)
93
    {
94
        $resolvedValue = null;
95
        $rejectedReason = null;
96
        $promise->then(
97
            function ($value) use (&$resolvedValue) {
98
                $resolvedValue = $value;
99
            },
100
            function ($reason) use (&$rejectedReason) {
101
                $rejectedReason = $reason;
102
            }
103
        );
104
105
        if ($rejectedReason instanceof \Exception) {
106
            throw $rejectedReason;
107
        }
108
109
        return $resolvedValue;
110
    }
111
}
112