Completed
Push — master ( 5f2691...53c2bd )
by Enrico
03:49
created

StringCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 10 1
A testSimpleSuccessCompile() 0 11 1
A testUnexpectedType() 0 11 1
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
9
class StringCastTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(true, "1"),
18
            array(0, "0"),
19
            array(-1, "-1"),
20
            array(1.4, "1.4"),
21
            array("a", "a"),
22
        );
23
    }
24
25
    /**
26
     * Tests (string) {expr} = {expr}
27
     *
28
     * @dataProvider getDataProvider
29
     */
30
    public function testSimpleSuccessCompile($a, $b)
31
    {
32
        $baseExpression = new Node\Expr\Cast\String_(
33
            $this->newScalarExpr($a)
34
        );
35
        $compiledExpression = $this->compileExpression($baseExpression);
36
37
        $this->assertInstanceOfCompiledExpression($compiledExpression);
38
        $this->assertSame(CompiledExpression::STRING, $compiledExpression->getType());
39
        $this->assertSame($b, $compiledExpression->getValue());
40
    }
41
42
    public function testUnexpectedType()
43
    {
44
        $baseExpression = new Node\Expr\Cast\String_(
45
            $this->newFakeScalarExpr()
46
        );
47
        $compiledExpression = $this->compileExpression($baseExpression);
48
49
        $this->assertInstanceOfCompiledExpression($compiledExpression);
50
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
51
        $this->assertSame(null, $compiledExpression->getValue());
52
    }
53
}
54