|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Compiler\Expression\BinaryOp; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PhpParser\Node\Name; |
|
7
|
|
|
use PHPSA\CompiledExpression; |
|
8
|
|
|
use PHPSA\Compiler\Expression; |
|
9
|
|
|
use PHPSA\Variable as Variable; |
|
10
|
|
|
use PhpParser\Node\Expr\Variable as VariableNode; |
|
11
|
|
|
|
|
12
|
|
|
class CoalesceTest extends \Tests\PHPSA\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testCoalesceVarInt() |
|
15
|
|
|
{ |
|
16
|
|
|
$context = $this->getContext(); |
|
17
|
|
|
$context->addVariable(new Variable("name", 10, CompiledExpression::INTEGER)); |
|
18
|
|
|
|
|
19
|
|
|
$variable = new VariableNode("name"); |
|
20
|
|
|
$else = parent::newScalarExpr("else"); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Coalesce($variable, $else); |
|
23
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $context); |
|
24
|
|
|
|
|
25
|
|
|
parent::assertInstanceOfCompiledExpression($compiledExpression); |
|
|
|
|
|
|
26
|
|
|
parent::assertSame(CompiledExpression::INTEGER, $compiledExpression->getType()); |
|
|
|
|
|
|
27
|
|
|
parent::assertSame(10, $compiledExpression->getValue()); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testCoalesceVarNull() |
|
31
|
|
|
{ |
|
32
|
|
|
$context = $this->getContext(); |
|
33
|
|
|
$context->addVariable(new Variable("name", null, CompiledExpression::NULL)); |
|
34
|
|
|
|
|
35
|
|
|
$variable = new VariableNode(new Name("name")); |
|
36
|
|
|
$else = parent::newScalarExpr("else"); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Coalesce($variable, $else); |
|
39
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $context); |
|
40
|
|
|
|
|
41
|
|
|
parent::assertInstanceOfCompiledExpression($compiledExpression); |
|
|
|
|
|
|
42
|
|
|
parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); |
|
|
|
|
|
|
43
|
|
|
parent::assertSame("else", $compiledExpression->getValue()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testCoalesceVarNotExisting() |
|
47
|
|
|
{ |
|
48
|
|
|
$context = $this->getContext(); |
|
49
|
|
|
|
|
50
|
|
|
$variable = new VariableNode(new Name("name")); |
|
51
|
|
|
$else = parent::newScalarExpr("else"); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Coalesce($variable, $else); |
|
54
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $context); |
|
55
|
|
|
|
|
56
|
|
|
parent::assertInstanceOfCompiledExpression($compiledExpression); |
|
|
|
|
|
|
57
|
|
|
parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); |
|
|
|
|
|
|
58
|
|
|
parent::assertSame("else", $compiledExpression->getValue()); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
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:
The
getFirstName()method in theSoncalls the wrong method in the parent class.