PostIncTest::testSuccessFromDataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 18
rs 9.6666
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
use PHPSA\Variable;
9
10
/**
11
 * Class PostIncTest
12
 * @package Tests\PHPSA\Expression\BinaryOp
13
 */
14
class PostIncTest extends \Tests\PHPSA\TestCase
15
{
16
    /**
17
     * @return array
18
     */
19
    public function getDataProviderForSuccess()
20
    {
21
        return [
22
            [-1],
23
            [1],
24
            [99],
25
            [0],
26
        ];
27
    }
28
29
    /**
30
     * @dataProvider getDataProviderForSuccess
31
     */
32
    public function testSuccessFromDataProvider($value)
33
    {
34
        $testVariableName = 'myTestVariable';
35
36
        $context = $this->getContext();
37
        $context->addVariable(new Variable($testVariableName, $value, CompiledExpression::INTEGER));
38
39
        $baseExpression = new Node\Expr\PostInc(
40
            new Node\Expr\Variable(
41
                new Node\Name($testVariableName)
42
            )
43
        );
44
        $compiledExpression = $this->compileExpression($baseExpression, $context);
45
46
        self::assertInstanceOfCompiledExpression($compiledExpression);
47
        self::assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
48
        self::assertSame(++$value, $compiledExpression->getValue());
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getDataProviderForSuccessDouble()
55
    {
56
        return [
57
            [-1.4],
58
            [1.4],
59
            [99.4],
60
            [0.4],
61
        ];
62
    }
63
64
    /**
65
     * @dataProvider getDataProviderForSuccessDouble
66
     */
67
    public function testSuccessDoubleFromDataProvider($value)
68
    {
69
        $testVariableName = 'myTestVariable';
70
71
        $context = $this->getContext();
72
        $context->addVariable(new Variable($testVariableName, $value, CompiledExpression::DOUBLE));
73
74
        $baseExpression = new Node\Expr\PostInc(
75
            new Node\Expr\Variable(
76
                new Node\Name($testVariableName)
77
            )
78
        );
79
        $compiledExpression = $this->compileExpression($baseExpression, $context);
80
81
        self::assertInstanceOfCompiledExpression($compiledExpression);
82
        self::assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
83
        self::assertSame(++$value, $compiledExpression->getValue());
84
    }
85
}
86