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 ( 628320...193300 )
by Jérémiah
14:48
created

getAuthorizationCheckerIsGrantedWithExpectation()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 3
1
<?php
2
3
namespace Overblog\GraphQLBundle\Tests\ExpressionLanguage;
4
5
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage;
6
use Overblog\GraphQLBundle\Tests\DIContainerMockTrait;
7
use PHPUnit\Framework\TestCase as BaseTestCase;
8
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
9
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
10
11
abstract class TestCase extends BaseTestCase
12
{
13
    use DIContainerMockTrait;
14
15
    /** @var ExpressionLanguage */
16
    protected $expressionLanguage;
17
18
    public function setUp()
19
    {
20
        $this->expressionLanguage = new ExpressionLanguage();
21
        $container = $this->getDIContainerMock();
22
        $this->expressionLanguage->setContainer($container);
23
        foreach ($this->getFunctions() as $function) {
24
            $this->expressionLanguage->addFunction($function);
25
        }
26
    }
27
28
    /**
29
     * @return ExpressionFunction[]
30
     */
31
    abstract protected function getFunctions();
32
33
    protected function assertExpressionCompile($expression, $with, array $expressionValues = [], $expects = null, $return = true, $assertMethod = 'assertTrue')
34
    {
35
        $expressionValues['container'] = $this->getDIContainerMock(['security.authorization_checker' => $this->getAuthorizationCheckerIsGrantedWithExpectation($with, $expects, $return)]);
36
        extract($expressionValues);
37
38
        $code = $this->expressionLanguage->compile($expression, array_keys($expressionValues));
39
40
        $this->$assertMethod(eval('return '.$code.';'));
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
41
    }
42
43
    private function getAuthorizationCheckerIsGrantedWithExpectation($with, $expects = null, $return = true)
44
    {
45
        if (null === $expects) {
46
            $expects = $this->once();
47
        }
48
        $authChecker = $this->getAuthorizationCheckerMock();
49
50
        if ($return instanceof \PHPUnit_Framework_MockObject_Stub_Return) {
0 ignored issues
show
Bug introduced by
The class PHPUnit_Framework_MockObject_Stub_Return does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
            $returnValue = $return;
52
        } else {
53
            $returnValue = $this->returnValue($return);
54
        }
55
56
        $methodExpectation = $authChecker
57
            ->expects($expects)
58
            ->method('isGranted');
59
60
        call_user_func_array([$methodExpectation, 'with'], is_array($with) ? $with : [$with]);
61
62
        $methodExpectation->will($returnValue);
63
64
        return $authChecker;
65
    }
66
67
    private function getAuthorizationCheckerMock()
68
    {
69
        $AuthorizationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)
70
            ->disableOriginalConstructor()
71
            ->setMethods(['isGranted'])
72
            ->getMock()
73
        ;
74
75
        return $AuthorizationChecker;
76
    }
77
}
78