Completed
Pull Request — master (#124)
by Enrico
03:58
created

UnaryMinusTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProviderForSuccess() 0 13 1
A testSuccessFromDataProvider() 0 11 1
A getDataProviderForUnsupported() 0 6 1
A testUnsupportedOperandType() 0 11 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Operators;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
/**
10
 * Class UnaryMinusTest
11
 * @package Tests\PHPSA\Expression\BinaryOp
12
 */
13
class UnaryMinusTest extends \Tests\PHPSA\TestCase
14
{
15
    /**
16
     * @return array
17
     */
18
    public function getDataProviderForSuccess()
19
    {
20
        return array(
21
            array(-1),
22
            array(1),
23
            array(true),
24
            array(false),
25
            array("test string"),
26
            array("10test string"),
27
            array(""),
28
            array(null),
29
        );
30
    }
31
32
    /**
33
     * @dataProvider getDataProviderForSuccess
34
     */
35
    public function testSuccessFromDataProvider($value)
36
    {
37
        $baseExpression = new Node\Expr\UnaryMinus(
38
            $this->newScalarExpr($value)
39
        );
40
        $compiledExpression = $this->compileExpression($baseExpression);
41
42
        $this->assertInstanceOfCompiledExpression($compiledExpression);
43
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
44
        $this->assertSame(- (int) $value, $compiledExpression->getValue());
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getDataProviderForUnsupported()
51
    {
52
        return array(
53
            array([]),
54
        );
55
    }
56
57
    /**
58
     * @dataProvider getDataProviderForUnsupported
59
     */
60
    public function testUnsupportedOperandType($value)
61
    {
62
        $baseExpression = new Node\Expr\UnaryMinus(
63
            $this->newScalarExpr($value)
64
        );
65
        $compiledExpression = $this->compileExpression($baseExpression);
66
67
        $this->assertInstanceOfCompiledExpression($compiledExpression);
68
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
69
        $this->assertSame(null, $compiledExpression->getValue());
70
    }
71
}
72