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

UnaryMinusTest::getDataProviderForUnsupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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