Completed
Pull Request — master (#304)
by Enrico
03:09
created

ConcatTest::buildExpression()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nop 2
rs 10
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
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp;
9
10
class ConcatTest extends AbstractBinaryOp
11
{
12
    /**
13
     * Data provider for {var} .= {expr} with result type = string
14
     *
15
     * @return array
16
     */
17
    public function concatDataProvider()
18
    {
19
        return [
20
            [2, 2, "22"],
21
            [true, "a", "1a"],
22
            ["a", true, "a1"],
23
            [true, true, "11"],
24
            [-1, 1, "-11"],
25
            [false, 3, "3"], // 0 at beginning is dropped
26
            [false, true, "1"],
27
            [0, -1, "0-1"],
28
            [1.5, -1, "1.5-1"],
29
            [true, -0.5, "1-0.5"],
30
            [false, false, ""],
31
            [true, false, "1"],
32
        ];
33
    }
34
35
    /**
36
     * Tests {var} .= {expr} with result type = string
37
     *
38
     * @dataProvider concatDataProvider
39
     */
40
    public function testConcatResultString($a, $b, $c)
41
    {
42
43
        $baseExpression = new Node\Expr\AssignOp\Concat(
44
            $this->newScalarExpr($a),
45
            $this->newScalarExpr($b)
46
        );
47
        $compiledExpression = $this->compileExpression($baseExpression);
48
49
        $this->assertInstanceOfCompiledExpression($compiledExpression);
50
        $this->assertSame(CompiledExpression::STRING, $compiledExpression->getType());
51
        $this->assertSame($c, $compiledExpression->getValue());
52
    }
53
54
    /**
55
     * @param Node\Scalar $a
56
     * @param Node\Scalar $b
57
     * @return Node\Expr\AssignOp\Concat
58
     */
59
    protected function buildExpression($a, $b)
60
    {
61
        return new Node\Expr\AssignOp\Concat($a, $b);
62
    }
63
}
64