Completed
Pull Request — master (#304)
by Enrico
02:53
created

AbstractUnaryOp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
buildExpression() 0 1 ?
process() 0 1 ?
getSupportedTypes() 0 1 ?
A testOperatorCompile() 0 13 2
A testUnexpectedType() 0 11 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
abstract class AbstractUnaryOp extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * Data provider for tests
13
     */
14
    public $data = [
15
            CompiledExpression::INTEGER => 6,
16
            CompiledExpression::DOUBLE => 2.5,
17
            CompiledExpression::STRING => "test",
18
            CompiledExpression::BOOLEAN => true,
19
            CompiledExpression::NULL => null,
20
        ];
21
22
    /**
23
     * @param $a
24
     * @return Node\Expr
25
     */
26
    abstract protected function buildExpression($a);
27
28
    /**
29
     * @param $a
30
     * @return mixed
31
     */
32
    abstract protected function process($a);
33
34
    /**
35
     * @return array
36
     */
37
    abstract protected function getSupportedTypes();
38
39
    /**
40
     * Tests $operator {expr}
41
     */
42
    public function testOperatorCompile()
43
    {
44
        foreach ($this->getSupportedTypes() as $type) {
45
            $baseExpression = $this->buildExpression(
46
                $this->newScalarExpr($this->data[$type])
47
            );
48
            $compiledExpression = $this->compileExpression($baseExpression);
49
50
            $this->assertInstanceOfCompiledExpression($compiledExpression);
51
            //$this->assertSame($this->getExpressionType($a), $compiledExpression->getType());
52
            $this->assertEquals($this->process($this->data[$type]), $compiledExpression->getValue());
53
        }
54
    }
55
56
    /**
57
     * Tests $operator {expr::UNKNOWN}
58
     */
59
    public function testUnexpectedType()
60
    {
61
        $baseExpression = $this->buildExpression(
62
            $this->newFakeScalarExpr()
63
        );
64
        $compiledExpression = $this->compileExpression($baseExpression);
65
66
        $this->assertInstanceOfCompiledExpression($compiledExpression);
67
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
68
        $this->assertSame(null, $compiledExpression->getValue());
69
    }
70
}
71