GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1978d2...e2f699 )
by William
03:55
created

Tests/Expression/LinkExpressionFunctionTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Hateoas\Tests\Expression;
4
5
use Hateoas\Expression\ExpressionEvaluator;
6
use Hateoas\Expression\LinkExpressionFunction;
7
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
8
9
class LinkExpressionFunctionTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testEvaluate()
12
    {
13
        $object = new \StdClass();
14
15
        $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
16
17
        $expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage());
18
        $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
19
20
        $this->assertEquals(
21
            '/foo',
22
            $expressionEvaluator->evaluate('expr(link(object, "self", false))', $object)
23
        );
24
    }
25
26
    public function testCompile()
27
    {
28
        $object = new \StdClass();
29
30
        $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
31
32
        $expressionLanguage = new ExpressionLanguage();
33
        $expressionEvaluator = new ExpressionEvaluator($expressionLanguage);
34
        $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
35
36
        $compiledExpression = $expressionLanguage->compile('link(object, "self", false)', array('object', 'link_helper'));
37
38
        // setup variables for expression eval
39
        $object = $object;
0 ignored issues
show
Why assign $object to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
40
        $link_helper = $linkHelperMock;
0 ignored issues
show
$link_helper is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
42
        $this->assertEquals('/foo', eval(sprintf('return %s;', $compiledExpression)));
43
    }
44
45
    /**
46
     * @param string $result
47
     * @param \stdClass $expectedObject
48
     * @param string $expectedRel
49
     * @param boolean $expectedAbsolute
50
     *
51
     * @return \Hateoas\Helper\LinkHelper
52
     */
53
    private function mockHelper($result, $expectedObject, $expectedRel, $expectedAbsolute)
54
    {
55
        $linkHelperMock = $this
56
            ->getMockBuilder('Hateoas\Helper\LinkHelper')
57
            ->disableOriginalConstructor()
58
            ->getMock()
59
        ;
60
61
        $linkHelperMock
62
            ->expects($this->once())
63
            ->method('getLinkHref')
64
            ->will($this->returnValue('/foo'))
65
            ->with($expectedObject, $expectedRel, $expectedAbsolute)
66
        ;
67
68
        return $linkHelperMock;
69
    }
70
}
71