Completed
Pull Request — master (#304)
by Enrico
03:09
created

AbstractBinaryOp::buildExpression()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
abstract class AbstractBinaryOp extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @param $a
13
     * @param $b
14
     * @return Node\Expr
15
     */
16
    abstract protected function buildExpression($a, $b);
17
18
    /**
19
     * Tests {left-expr::UNKNOWN} $operator {right-expr}
20
     */
21
    public function testFirstArgUnexpectedType()
22
    {
23
        $baseExpression = $this->buildExpression(
24
            $this->newFakeScalarExpr(),
25
            $this->newScalarExpr(1)
26
        );
27
        $compiledExpression = $this->compileExpression($baseExpression);
28
29
        $this->assertInstanceOfCompiledExpression($compiledExpression);
30
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
31
        $this->assertSame(null, $compiledExpression->getValue());
32
    }
33
34
    /**
35
     * Tests {left-expr} $operator {right-expr::UNKNOWN}
36
     */
37
    public function testSecondArgUnexpectedType()
38
    {
39
        $baseExpression = $this->buildExpression(
40
            $this->newScalarExpr(1),
41
            $this->newFakeScalarExpr()
42
        );
43
        $compiledExpression = $this->compileExpression($baseExpression);
44
45
        $this->assertInstanceOfCompiledExpression($compiledExpression);
46
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
47
        $this->assertSame(null, $compiledExpression->getValue());
48
    }
49
}
50