|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\PHPSA; |
|
4
|
|
|
|
|
5
|
|
|
use PHPSA\CompiledExpression; |
|
6
|
|
|
|
|
7
|
|
|
class CompiledExpressionTest extends TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testToVariableMethod() |
|
10
|
|
|
{ |
|
11
|
|
|
$compiledExpression = new CompiledExpression(CompiledExpression::INTEGER, 1); |
|
12
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
13
|
|
|
|
|
14
|
|
|
$resultVariable = $compiledExpression->toVariable('test'); |
|
15
|
|
|
static::assertInstanceOf('PHPSA\Variable', $resultVariable); |
|
16
|
|
|
static::assertSame($compiledExpression->getType(), $resultVariable->getType()); |
|
17
|
|
|
static::assertSame($compiledExpression->getValue(), $resultVariable->getValue()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testFromZvalInteger() |
|
21
|
|
|
{ |
|
22
|
|
|
$result = CompiledExpression::fromZvalValue(1); |
|
23
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
24
|
|
|
$this->assertSame(CompiledExpression::INTEGER, $result->getType()); |
|
25
|
|
|
$this->assertSame(1, $result->getValue()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testFromZvalBoolean() |
|
29
|
|
|
{ |
|
30
|
|
|
$result = CompiledExpression::fromZvalValue(true); |
|
31
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
32
|
|
|
$this->assertSame(CompiledExpression::BOOLEAN, $result->getType()); |
|
33
|
|
|
$this->assertSame(true, $result->getValue()); |
|
34
|
|
|
|
|
35
|
|
|
$result = CompiledExpression::fromZvalValue(false); |
|
36
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
37
|
|
|
$this->assertSame(CompiledExpression::BOOLEAN, $result->getType()); |
|
38
|
|
|
$this->assertSame(false, $result->getValue()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testFromZvalArray() |
|
42
|
|
|
{ |
|
43
|
|
|
$result = CompiledExpression::fromZvalValue([]); |
|
44
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
45
|
|
|
$this->assertSame(CompiledExpression::ARR, $result->getType()); |
|
46
|
|
|
$this->assertSame([], $result->getValue()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testFromZvalString() |
|
50
|
|
|
{ |
|
51
|
|
|
$result = CompiledExpression::fromZvalValue("test string"); |
|
52
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
53
|
|
|
$this->assertSame(CompiledExpression::STRING, $result->getType()); |
|
54
|
|
|
$this->assertSame("test string", $result->getValue()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFromZvalDouble() |
|
58
|
|
|
{ |
|
59
|
|
|
$result = CompiledExpression::fromZvalValue(1.0); |
|
60
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
61
|
|
|
$this->assertSame(CompiledExpression::DOUBLE, $result->getType()); |
|
62
|
|
|
$this->assertSame(1.0, $result->getValue()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testFromZvalNull() |
|
66
|
|
|
{ |
|
67
|
|
|
$result = CompiledExpression::fromZvalValue(null); |
|
68
|
|
|
$this->assertInstanceOfCompiledExpression($result); |
|
69
|
|
|
$this->assertSame(CompiledExpression::NULL, $result->getType()); |
|
70
|
|
|
$this->assertSame(null, $result->getValue()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testCanBeObject() |
|
74
|
|
|
{ |
|
75
|
|
|
// Mixed type can be object |
|
76
|
|
|
$expr = new CompiledExpression(CompiledExpression::MIXED, null); |
|
77
|
|
|
$this->assertSame(true, $expr->canBeObject()); |
|
78
|
|
|
|
|
79
|
|
|
// Integer type can't be object |
|
80
|
|
|
$expr2 = new CompiledExpression(CompiledExpression::INTEGER, 1); |
|
81
|
|
|
$this->assertSame(false, $expr2->canBeObject()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testIsObject() |
|
85
|
|
|
{ |
|
86
|
|
|
// Mixed type could be object but it's unclear |
|
87
|
|
|
$expr = new CompiledExpression(CompiledExpression::MIXED, null); |
|
88
|
|
|
$this->assertSame(false, $expr->isObject()); |
|
89
|
|
|
|
|
90
|
|
|
// Object type is object |
|
91
|
|
|
$expr2 = new CompiledExpression(CompiledExpression::OBJECT, null); |
|
92
|
|
|
$this->assertSame(true, $expr2->isObject()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|