|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Compiler\Expression\AssignOp; |
|
4
|
|
|
|
|
5
|
|
|
use PhpParser\Node; |
|
6
|
|
|
use PHPSA\CompiledExpression; |
|
7
|
|
|
use PHPSA\Compiler\Expression; |
|
8
|
|
|
|
|
9
|
|
|
class ConcatTest extends \Tests\PHPSA\TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Data provider for {var} .= {expr} with result type = string |
|
13
|
|
|
* |
|
14
|
|
|
* @return array |
|
15
|
|
|
*/ |
|
16
|
|
|
public function concatDataProvider() |
|
17
|
|
|
{ |
|
18
|
|
|
return array( |
|
19
|
|
|
array(2, 2, "22"), |
|
20
|
|
|
array(true, "a", "1a"), |
|
21
|
|
|
array("a", true, "a1"), |
|
22
|
|
|
array(true, true, "11"), |
|
23
|
|
|
array(-1, 1, "-11"), |
|
24
|
|
|
array(false, 3, "3"), // 0 at beginning is dropped |
|
25
|
|
|
array(false, true, "1"), |
|
26
|
|
|
array(0, -1, "0-1"), |
|
27
|
|
|
array(1.5, -1, "1.5-1"), |
|
28
|
|
|
array(true, -0.5, "1-0.5"), |
|
29
|
|
|
array(false, false, ""), |
|
30
|
|
|
array(true, false, "1"), |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Tests {var} .= {expr} with result type = string |
|
36
|
|
|
* |
|
37
|
|
|
* @dataProvider concatDataProvider |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testConcatResultString($a, $b, $c) |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
$baseExpression = new Node\Expr\AssignOp\Concat( |
|
43
|
|
|
$this->newScalarExpr($a), |
|
44
|
|
|
$this->newScalarExpr($b) |
|
45
|
|
|
); |
|
46
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
49
|
|
|
$this->assertSame(CompiledExpression::STRING, $compiledExpression->getType()); |
|
50
|
|
|
$this->assertSame($c, $compiledExpression->getValue()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Tests {var-type::UNKNOWN} .= {right-expr} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testFirstUnexpectedType() |
|
57
|
|
|
{ |
|
58
|
|
|
$baseExpression = new Node\Expr\AssignOp\Concat( |
|
59
|
|
|
$this->newFakeScalarExpr(), |
|
60
|
|
|
$this->newScalarExpr(1) |
|
61
|
|
|
); |
|
62
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
65
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
|
66
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Tests {var} .= {right-expr::UNKNOWN} |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testSecondUnexpectedType() |
|
73
|
|
|
{ |
|
74
|
|
|
$baseExpression = new Node\Expr\AssignOp\Concat( |
|
75
|
|
|
$this->newScalarExpr(1), |
|
76
|
|
|
$this->newFakeScalarExpr() |
|
77
|
|
|
); |
|
78
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
81
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
|
82
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|