1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Expression\BinaryOp; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PHPSA\CompiledExpression; |
7
|
|
|
use PHPSA\Compiler\Expression; |
8
|
|
|
|
9
|
|
|
class SpaceShipTest extends \Tests\PHPSA\TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return array |
13
|
|
|
*/ |
14
|
|
|
public function getDataProvider() |
15
|
|
|
{ |
16
|
|
|
return array( |
17
|
|
|
array(1, 1, 0), |
18
|
|
|
array(1, 2, -1), |
19
|
|
|
array(2, 1, 1), |
20
|
|
|
array(true, false, 1), |
21
|
|
|
array(true, 0, 1), |
22
|
|
|
array(array(), array(), 0), |
23
|
|
|
array(true, array(), 1), |
24
|
|
|
array("a", "b", -1), |
25
|
|
|
array("a", 2, -1), |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Tests {expr} <=> {expr} = {expr} |
31
|
|
|
* |
32
|
|
|
* @dataProvider getDataProvider |
33
|
|
|
*/ |
34
|
|
|
public function testSimpleSuccessCompile($a, $b, $c) |
35
|
|
|
{ |
36
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Spaceship( |
37
|
|
|
$this->newScalarExpr($a), |
38
|
|
|
$this->newScalarExpr($b) |
39
|
|
|
); |
40
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
43
|
|
|
$this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType()); |
44
|
|
|
$this->assertSame($c, $compiledExpression->getValue()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testUnexpectedTypeFirstArg() |
48
|
|
|
{ |
49
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Spaceship( |
50
|
|
|
$this->newFakeScalarExpr(), |
51
|
|
|
$this->newScalarExpr(1) |
52
|
|
|
); |
53
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
54
|
|
|
|
55
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
56
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
57
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testUnexpectedTypeSecondArg() |
61
|
|
|
{ |
62
|
|
|
$baseExpression = new Node\Expr\BinaryOp\Spaceship( |
63
|
|
|
$this->newScalarExpr(1), |
64
|
|
|
$this->newFakeScalarExpr() |
65
|
|
|
); |
66
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
67
|
|
|
|
68
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
69
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
70
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|