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 (#264)
by Jérémiah
12:16
created

TestCase::sendRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\Functional;
4
5
use Overblog\GraphQLBundle\Tests\Functional\App\TestKernel;
6
use Symfony\Bundle\FrameworkBundle\Client;
7
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * TestCase.
13
 */
14
abstract class TestCase extends WebTestCase
15
{
16
    const USER_RYAN = 'ryan';
17
    const USER_ADMIN = 'admin';
18
    const ANONYMOUS_USER = null;
19
    const DEFAULT_PASSWORD = '123';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected static function getKernelClass()
25
    {
26
        return TestKernel::class;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected static function createKernel(array $options = [])
33
    {
34
        if (null === static::$class) {
35
            static::$class = static::getKernelClass();
36
        }
37
38
        $options['test_case'] = isset($options['test_case']) ? $options['test_case'] : null;
39
40
        $env = isset($options['environment']) ? $options['environment'] : 'test'.strtolower($options['test_case']);
41
        $debug = isset($options['debug']) ? $options['debug'] : true;
42
43
        return new static::$class($env, $debug, $options['test_case']);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public static function setUpBeforeClass()
50
    {
51
        $fs = new Filesystem();
52
        $fs->remove(sys_get_temp_dir().'/OverblogGraphQLBundle/');
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function tearDown()
59
    {
60
        static::$kernel = null;
61
    }
62
63
    protected static function executeGraphQLRequest($query, $rootValue = [], $throwException = false)
64
    {
65
        $request = new Request();
66
        $request->query->set('query', $query);
67
68
        $req = static::getContainer()->get('overblog_graphql.request_parser')->parse($request);
69
        static::getContainer()->get('error_handler_listener')->setThrowException($throwException);
70
        $res = static::getContainer()->get('overblog_graphql.request_executor')->execute(null, $req, $rootValue);
71
72
        return $res->toArray();
73
    }
74
75
    protected static function assertGraphQL($query, array $expectedData = null, array $expectedErrors = null, $rootValue = [])
76
    {
77
        $result = static::executeGraphQLRequest($query, $rootValue, true);
78
79
        $expected = [];
80
81
        if (null !== $expectedData) {
82
            $expected['data'] = $expectedData;
83
        }
84
85
        if (null !== $expectedErrors) {
86
            $expected['errors'] = $expectedErrors;
87
        }
88
89
        static::assertEquals($expected, $result, json_encode($result));
90
    }
91
92
    protected static function getContainer()
93
    {
94
        return static::$kernel->getContainer();
95
    }
96
97
    protected static function query($query, $username, $testCase, $password = self::DEFAULT_PASSWORD)
98
    {
99
        $client = static::createClientAuthenticated($username, $testCase, $password);
100
        $client->request('GET', '/', ['query' => $query]);
101
102
        return $client;
103
    }
104
105
    protected static function createClientAuthenticated($username, $testCase, $password = self::DEFAULT_PASSWORD)
106
    {
107
        $client = static::createClient(['test_case' => $testCase]);
108
109
        if ($username) {
110
            $client->setServerParameters([
111
                'PHP_AUTH_USER' => $username,
112
                'PHP_AUTH_PW' => $password,
113
            ]);
114
        }
115
116
        return $client;
117
    }
118
119
    protected static function assertResponse($query, array $expected, $username, $testCase, $password = self::DEFAULT_PASSWORD)
120
    {
121
        $client = self::createClientAuthenticated($username, $testCase, $password);
122
        $result = self::sendRequest($client, $query);
123
124
        static::assertEquals($expected, json_decode($result, true), $result);
125
126
        return $client;
127
    }
128
129
    protected static function sendRequest(Client $client, $query, $isDecoded = false)
130
    {
131
        $client->request('GET', '/', ['query' => $query]);
132
        $result = $client->getResponse()->getContent();
133
134
        return $isDecoded ? json_decode($result, true) : $result;
135
    }
136
}
137