Completed
Pull Request — master (#186)
by Дмитрий
14:18 queued 08:57
created

g::getDataProviderWithFunctionCallExpr()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 43
rs 8.8571
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 g extends \Tests\PHPSA\TestCase
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
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