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
Push — master ( b6fc5f...138f00 )
by Jérémiah
03:34
created

testMaskErrorWithWrappedUserErrorAndThrowExceptionSetToTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 22
Ratio 100 %
Metric Value
dl 22
loc 22
rs 9.2
cc 1
eloc 10
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\Error;
13
14
use GraphQL\Error;
15
use GraphQL\Executor\ExecutionResult;
16
use Overblog\GraphQLBundle\Error\ErrorHandler;
17
use Overblog\GraphQLBundle\Error\UserError;
18
use Overblog\GraphQLBundle\Error\UserErrors;
19
20
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
21
{
22
    /** @var ErrorHandler */
23
    private $errorHandler;
24
25
    public function setUp()
26
    {
27
        $this->errorHandler = new ErrorHandler();
28
    }
29
30
    public function testMaskErrorWithThrowExceptionSetToFalse()
31
    {
32
        $executionResult = new ExecutionResult(
33
            null,
34
            [
35
                new Error('Error without wrapped exception'),
36
                new Error('Error with wrapped exception', null, new \Exception('My Exception message')),
37
                new Error('Error with wrapped user error', null, new UserError('My User Error')),
38
                new Error('', null, new UserErrors(['My User Error 1', 'My User Error 2', new UserError('My User Error 3')])),
39
            ]
40
        );
41
42
        $this->errorHandler->handleErrors($executionResult);
43
44
        $expected = [
45
            'data'   => null,
46
            'errors' => [
47
                [
48
                    'message' => 'Error without wrapped exception',
49
                ],
50
                [
51
                    'message' => ErrorHandler::DEFAULT_ERROR_MESSAGE,
52
                ],
53
                [
54
                    'message' => 'Error with wrapped user error',
55
                ],
56
                [
57
                    'message' => 'My User Error 1',
58
                ],
59
                [
60
                    'message' => 'My User Error 2',
61
                ],
62
                [
63
                    'message' => 'My User Error 3',
64
                ],
65
            ],
66
        ];
67
68
        $this->assertEquals($expected, $executionResult->toArray());
69
    }
70
71
    /**
72
     * @expectedException \Exception
73
     * @expectedExceptionMessage My Exception message
74
     */
75
    public function testMaskErrorWithWrappedExceptionAndThrowExceptionSetToTrue()
76
    {
77
        $executionResult = new ExecutionResult(
78
            null,
79
            [
80
                new Error('Error with wrapped exception', null, new \Exception('My Exception message')),
81
            ]
82
        );
83
84
        $this->errorHandler->handleErrors($executionResult, true);
85
    }
86
87 View Code Duplication
    public function testMaskErrorWithWrappedUserErrorAndThrowExceptionSetToTrue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $executionResult = new ExecutionResult(
90
            null,
91
            [
92
                new Error('Error with wrapped user error', null, new UserError('My User Error')),
93
            ]
94
        );
95
96
        $this->errorHandler->handleErrors($executionResult, true);
97
98
        $expected = [
99
            'data'   => null,
100
            'errors' => [
101
                [
102
                    'message' => 'Error with wrapped user error',
103
                ],
104
            ],
105
        ];
106
107
        $this->assertEquals($expected, $executionResult->toArray());
108
    }
109
110 View Code Duplication
    public function testMaskErrorWithoutWrappedExceptionAndThrowExceptionSetToTrue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        $executionResult = new ExecutionResult(
113
            null,
114
            [
115
                new Error('Error without wrapped exception'),
116
            ]
117
        );
118
119
        $this->errorHandler->handleErrors($executionResult, true);
120
121
        $expected = [
122
            'data'   => null,
123
            'errors' => [
124
                [
125
                    'message' => 'Error without wrapped exception',
126
                ],
127
            ],
128
        ];
129
130
        $this->assertEquals($expected, $executionResult->toArray());
131
    }
132
133
    public function testMaskErrorOverrideErrorHandle()
134
    {
135
        $executionResult = new ExecutionResult(
136
            null,
137
            [
138
                new Error('Error without wrapped exception'),
139
            ]
140
        );
141
142
        $this->errorHandler->setErrorHandler(function () {
143
            return [new Error('Override Error')];
144
        });
145
146
        $this->errorHandler->handleErrors($executionResult);
147
148
        $expected = [
149
            'data'   => null,
150
            'errors' => [
151
                [
152
                    'message' => 'Override Error',
153
                ],
154
            ],
155
        ];
156
157
        $this->assertEquals($expected, $executionResult->toArray());
158
    }
159
}
160