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

testFindReturnStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 16
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
        $context->addVariable(
26
            new \PHPSA\Variable(
27
                'variableWithIntValue',
28
                12345,
29
                CompiledExpression::INTEGER
30
            )
31
        );
32
33
        return [
34
            // success
35
            [
36
                new \PhpParser\Node\Name(['testFn']),
37
                'testFn',
38
                $context
39
            ],
40
            [
41
                new \PhpParser\Node\Expr\Variable('variableWithFunctionName'),
42
                'testFunctionName',
43
                $context
44
            ],
45
            // not success
46
            [
47
                new \PhpParser\Node\Expr\Variable('unknown'),
48
                false,
49
                $context
50
            ],
51
            [
52
                new \PhpParser\Node\Expr\Variable('variableWithIntValue'),
53
                false,
54
                $context
55
            ],
56
        ];
57
    }
58
59
    /**
60
     * @dataProvider getDataProviderWithFunctionCallExpr
61
     *
62
     * @param $nameExpr
63
     * @param $expectedFunctionName
64
     */
65
    public function testResolveFunctionName($nameExpr, $expectedFunctionName, $context)
66
    {
67
        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...
68
            $expectedFunctionName,
69
            $this->resolveFunctionName(
70
                new \PhpParser\Node\Expr\FuncCall(
71
                    $nameExpr
72
                ),
73
                $context
74
            )
75
        );
76
    }
77
78
    public function testFindReturnStatement()
79
    {
80
        $returnStatement = new \PhpParser\Node\Stmt\Return_();
81
82
        parent::assertSame(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testFindReturnStatement()). 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...
83
            [$returnStatement],
84
            // findReturnStatement will return \Generator, We should iterate it
85
            iterator_to_array(
86
                $this->findReturnStatement(
87
                    [
88
                        $returnStatement
89
                    ]
90
                )
91
            )
92
        );
93
    }
94
95
    public function testFindYieldStatement()
96
    {
97
        $returnStatement = new \PhpParser\Node\Expr\Yield_();
98
99
        parent::assertSame(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testFindYieldStatement()). 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...
100
            [$returnStatement],
101
            // findReturnStatement will return \Generator, We should iterate it
102
            iterator_to_array(
103
                $this->findYieldExpression(
104
                    [
105
                        $returnStatement
106
                    ]
107
                )
108
            )
109
        );
110
    }
111
}
112