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

StringCastTest::testStringCastCompile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 11
c 0
b 0
f 0
cc 1
eloc 7
nop 2
rs 9.4285
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Casts;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
use Tests\PHPSA\Compiler\Expression\AbstractUnaryOp;
9
10
class StringCastTest extends AbstractUnaryOp
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getDataProvider()
16
    {
17
        return [
18
            [true, "1"],
19
            [0, "0"],
20
            [-1, "-1"],
21
            [1.4, "1.4"],
22
            ["a", "a"],
23
        ];
24
    }
25
26
    /**
27
     * Tests (string) {expr} = {expr}
28
     *
29
     * @dataProvider getDataProvider
30
     */
31
    public function testStringCastCompile($a, $b)
32
    {
33
        $baseExpression = new Node\Expr\Cast\String_(
34
            $this->newScalarExpr($a)
35
        );
36
        $compiledExpression = $this->compileExpression($baseExpression);
37
38
        $this->assertInstanceOfCompiledExpression($compiledExpression);
39
        $this->assertSame(CompiledExpression::STRING, $compiledExpression->getType());
40
        $this->assertSame($b, $compiledExpression->getValue());
41
    }
42
43
    /**
44
     * @param Node\Scalar $a
45
     * @return Node\Expr\Cast\String_
46
     */
47
    protected function buildExpression($a)
48
    {
49
        return new Node\Expr\Cast\String_($a);
50
    }
51
}
52