Completed
Pull Request — master (#149)
by Enrico
04:04
created

ForTest::testForInitCreatesVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 21
rs 9.3142
c 1
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Statement;
4
5
use PhpParser\Node;
6
use PHPSA\Variable;
7
8
class ForTest extends \Tests\PHPSA\TestCase
9
{
10
    /**
11
     * Tests for ($stmtTest = 2;;) {} creates the variable
12
     */
13
    public function testForInitCreatesVar()
14
    {
15
        $context = $this->getContext();
16
17
        $statement = new Node\Stmt\For_(
18
            ["init" =>
19
                [new Node\Expr\Assign(
20
                    new Node\Expr\Variable(
21
                        new Node\Name("stmtTest")
22
                    ),
23
                    $this->newScalarExpr(2)
24
                )]
25
            ]
26
        );
27
        
28
        \PHPSA\nodeVisitorFactory($statement, $context);
29
30
        $variable = $context->getSymbol("stmtTest");
31
32
        parent::assertTrue($variable instanceof Variable);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertTrue() instead of testForInitCreatesVar()). Are you sure this is correct? If so, you might want to change this to $this->assertTrue().

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...
33
    }
34
35
    /**
36
     * Tests for (;$stmtTest = 2;) {} creates the variable
37
     */
38
    public function testForConditionCreatesVar()
39
    {
40
        $context = $this->getContext();
41
42
        $statement = new Node\Stmt\For_(
43
            ["cond" =>
44
                [new Node\Expr\Assign(
45
                    new Node\Expr\Variable(
46
                        new Node\Name("stmtTest")
47
                    ),
48
                    $this->newScalarExpr(2)
49
                )]
50
            ]
51
        );
52
        
53
        \PHPSA\nodeVisitorFactory($statement, $context);
54
55
        $variable = $context->getSymbol("stmtTest");
56
57
        parent::assertTrue($variable instanceof Variable);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertTrue() instead of testForConditionCreatesVar()). Are you sure this is correct? If so, you might want to change this to $this->assertTrue().

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...
58
    }
59
60
    /**
61
     * Tests for (;$stmtTest = 2) {} creates the variable
62
     */
63
    public function testForLoopCreatesVar()
64
    {
65
        $context = $this->getContext();
66
67
        $statement = new Node\Stmt\For_(
68
            ["loop" =>
69
                [new Node\Expr\Assign(
70
                    new Node\Expr\Variable(
71
                        new Node\Name("stmtTest")
72
                    ),
73
                    $this->newScalarExpr(2)
74
                )]
75
            ]
76
        );
77
        
78
        \PHPSA\nodeVisitorFactory($statement, $context);
79
80
        $variable = $context->getSymbol("stmtTest");
81
82
        parent::assertTrue($variable instanceof Variable);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertTrue() instead of testForLoopCreatesVar()). Are you sure this is correct? If so, you might want to change this to $this->assertTrue().

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
    }
84
85
    /**
86
     * Tests for (;;) { $stmtTest = 2 } creates the variable
87
     */
88
    public function testForStatementCreatesVar()
89
    {
90
        $context = $this->getContext();
91
92
        $statement = new Node\Stmt\For_(
93
            ["stmts" =>
94
                [new Node\Expr\Assign(
95
                    new Node\Expr\Variable(
96
                        new Node\Name("stmtTest")
97
                    ),
98
                    $this->newScalarExpr(2)
99
                )]
100
            ]
101
        );
102
        
103
        \PHPSA\nodeVisitorFactory($statement, $context);
104
105
        $variable = $context->getSymbol("stmtTest");
106
107
        parent::assertTrue($variable instanceof Variable);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertTrue() instead of testForStatementCreatesVar()). Are you sure this is correct? If so, you might want to change this to $this->assertTrue().

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...
108
    }
109
}
110