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 AbstractUnaryOp extends \Tests\PHPSA\TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Data provider for tests |
13
|
|
|
*/ |
14
|
|
|
public $data = [ |
15
|
|
|
CompiledExpression::INTEGER => 6, |
16
|
|
|
CompiledExpression::DOUBLE => 2.5, |
17
|
|
|
CompiledExpression::STRING => "test", |
18
|
|
|
CompiledExpression::BOOLEAN => true, |
19
|
|
|
CompiledExpression::NULL => null, |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param $a |
24
|
|
|
* @return Node\Expr |
25
|
|
|
*/ |
26
|
|
|
abstract protected function buildExpression($a); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param $a |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
|
abstract protected function process($a); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
abstract protected function getSupportedTypes(); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Tests $operator {expr} |
41
|
|
|
*/ |
42
|
|
|
public function testOperatorCompile() |
43
|
|
|
{ |
44
|
|
|
foreach ($this->getSupportedTypes() as $type) { |
45
|
|
|
$baseExpression = $this->buildExpression( |
46
|
|
|
$this->newScalarExpr($this->data[$type]) |
47
|
|
|
); |
48
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
51
|
|
|
//$this->assertSame($this->getExpressionType($a), $compiledExpression->getType()); |
52
|
|
|
$this->assertEquals($this->process($this->data[$type]), $compiledExpression->getValue()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tests $operator {expr::UNKNOWN} |
58
|
|
|
*/ |
59
|
|
|
public function testUnexpectedType() |
60
|
|
|
{ |
61
|
|
|
$baseExpression = $this->buildExpression( |
62
|
|
|
$this->newFakeScalarExpr() |
63
|
|
|
); |
64
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
67
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
68
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|