DoTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDoConditionCreatesVar() 0 19 1
A testDoStatementCreatesVar() 0 21 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Statement;
4
5
use PhpParser\Node;
6
use PHPSA\Variable;
7
8
class DoTest extends \Tests\PHPSA\TestCase
9
{
10
    /**
11
     * Tests do {} while ($stmtTest = 2) creates the variable
12
     */
13
    public function testDoConditionCreatesVar()
14
    {
15
        $context = $this->getContext();
16
17
        $statement = new Node\Stmt\Do_(
18
            new Node\Expr\Assign(
19
                new Node\Expr\Variable(
20
                    new Node\Name("stmtTest")
21
                ),
22
                $this->newScalarExpr(2)
23
            )
24
        );
25
        
26
        \PHPSA\nodeVisitorFactory($statement, $context);
27
28
        $variable = $context->getSymbol("stmtTest");
29
30
        self::assertTrue($variable instanceof Variable);
31
    }
32
33
    /**
34
     * Tests do { $stmtTest = 2; } while (1 == 1) creates the variable
35
     */
36
    public function testDoStatementCreatesVar()
37
    {
38
        $context = $this->getContext();
39
40
        $statement = new Node\Stmt\Do_(
41
            new Node\Expr\BinaryOp\Equal($this->newScalarExpr(1), $this->newScalarExpr(1)),
42
            ["stmts" =>
43
                new Node\Expr\Assign(
44
                    new Node\Expr\Variable(
45
                        new Node\Name("stmtTest")
46
                    ),
47
                    $this->newScalarExpr(2)
48
                )]
49
        );
50
        
51
        \PHPSA\nodeVisitorFactory($statement, $context);
52
53
        $variable = $context->getSymbol("stmtTest");
54
55
        self::assertTrue($variable instanceof Variable);
56
    }
57
}
58