|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Expression; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PHPSA\CompiledExpression; |
|
7
|
|
|
use PHPSA\Compiler\Expression; |
|
8
|
|
|
|
|
9
|
|
|
class TernaryTest extends \Tests\PHPSA\TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testTernaryTrue() |
|
12
|
|
|
{ |
|
13
|
|
|
// (2 == 2) ? "if" : "else" |
|
14
|
|
|
$baseExpression = new Node\Expr\Ternary( |
|
15
|
|
|
new Node\Expr\BinaryOp\Equal($this->newScalarExpr(2), $this->newScalarExpr(2)), |
|
16
|
|
|
$this->newScalarExpr("if"), |
|
17
|
|
|
$this->newScalarExpr("else") |
|
18
|
|
|
); |
|
19
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
20
|
|
|
|
|
21
|
|
|
parent::assertInstanceOfCompiledExpression($compiledExpression); |
|
|
|
|
|
|
22
|
|
|
parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); |
|
|
|
|
|
|
23
|
|
|
parent::assertSame("if", $compiledExpression->getValue()); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testTernaryFalse() |
|
27
|
|
|
{ |
|
28
|
|
|
// (2 == 3) ? "if" : "else" |
|
29
|
|
|
$baseExpression = new Node\Expr\Ternary( |
|
30
|
|
|
new Node\Expr\BinaryOp\Equal($this->newScalarExpr(2), $this->newScalarExpr(3)), |
|
31
|
|
|
$this->newScalarExpr("if"), |
|
32
|
|
|
$this->newScalarExpr("else") |
|
33
|
|
|
); |
|
34
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
35
|
|
|
|
|
36
|
|
|
parent::assertInstanceOfCompiledExpression($compiledExpression); |
|
|
|
|
|
|
37
|
|
|
parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); |
|
|
|
|
|
|
38
|
|
|
parent::assertSame("else", $compiledExpression->getValue()); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
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.