ElseTest::testIfElseCreatesVar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 24
rs 9.536
c 0
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 ElseTest extends \Tests\PHPSA\TestCase
9
{
10
    /**
11
     * Tests if (1 == 2) { } else { $stmtTest = 2; } creates the variable
12
     */
13
    public function testIfElseCreatesVar()
14
    {
15
        $context = $this->getContext();
16
17
        $statement = new Node\Stmt\If_(
18
            new Node\Expr\BinaryOp\Equal($this->newScalarExpr(1), $this->newScalarExpr(2)),
19
            ["else" =>
20
                new Node\Stmt\Else_(
21
                    [new Node\Expr\Assign(
22
                        new Node\Expr\Variable(
23
                            new Node\Name("stmtTest")
24
                        ),
25
                        $this->newScalarExpr(2)
26
                    )]
27
                )
28
            ]
29
        );
30
        
31
        \PHPSA\nodeVisitorFactory($statement, $context);
32
33
        $variable = $context->getSymbol("stmtTest");
34
35
        self::assertTrue($variable instanceof Variable);
36
    }
37
}
38