Completed
Pull Request — master (#186)
by Дмитрий
11:02
created

testResolveFunctionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace Tests\PHPSA\Analyzer\Helper;
7
8
use PHPSA\Analyzer\Helper\ResolveExpressionTrait;
9
use PHPSA\CompiledExpression;
10
11
class ResolveExpressionTraitTest extends \Tests\PHPSA\TestCase
12
{
13
    use ResolveExpressionTrait;
14
15
    public function getDataProviderWithFunctionCallExpr()
16
    {
17
        $context = $this->getContext();
18
        $context->addVariable(
19
            new \PHPSA\Variable(
20
                'variableWithFunctionName',
21
                'testFunctionName',
22
                CompiledExpression::STRING
23
            )
24
        );
25
26
        return [
27
            [
28
                new \PhpParser\Node\Name(['testFn']),
29
                'testFn',
30
                $context
31
            ],
32
            [
33
                new \PhpParser\Node\Expr\Variable('unknown'),
34
                false,
35
                $context
36
            ],
37
            [
38
                new \PhpParser\Node\Expr\Variable('variableWithFunctionName'),
39
                'testFunctionName',
40
                $context
41
            ]
42
        ];
43
    }
44
45
    /**
46
     * @dataProvider getDataProviderWithFunctionCallExpr
47
     *
48
     * @param $nameExpr
49
     * @param $expectedFunctionName
50
     */
51
    public function testResolveFunctionName($nameExpr, $expectedFunctionName, $context)
52
    {
53
        parent::assertSame(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testResolveFunctionName()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
54
            $expectedFunctionName,
55
            $this->resolveFunctionName(
56
                new \PhpParser\Node\Expr\FuncCall(
57
                    $nameExpr
58
                ),
59
                $context
60
            )
61
        );
62
    }
63
}
64