Completed
Pull Request — master (#304)
by Enrico
03:09
created

SpaceShipTest::testUnexpectedTypeSecondArg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\BinaryOp;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp;
9
10
class SpaceShipTest extends AbstractBinaryOp
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getDataProvider()
16
    {
17
        return [
18
            [1, 1, 0],
19
            [1, 2, -1],
20
            [2, 1, 1],
21
            [true, false, 1],
22
            [true, 0, 1],
23
            [[], [], 0],
24
            [true, [], 1],
25
            ["a", "b", -1],
26
            ["a", 2, -1],
27
        ];
28
    }
29
30
    /**
31
     * Tests {expr} <=> {expr} = {expr}
32
     *
33
     * @dataProvider getDataProvider
34
     */
35
    public function testSimpleSuccessCompile($a, $b, $c)
36
    {
37
        $baseExpression = new Node\Expr\BinaryOp\Spaceship(
38
            $this->newScalarExpr($a),
39
            $this->newScalarExpr($b)
40
        );
41
        $compiledExpression = $this->compileExpression($baseExpression);
42
43
        $this->assertInstanceOfCompiledExpression($compiledExpression);
44
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
45
        $this->assertSame($c, $compiledExpression->getValue());
46
    }
47
48
    /**
49
     * @param Node\Scalar $a
50
     * @param Node\Scalar $b
51
     * @return Node\Expr\BinaryOp\Spaceship
52
     */
53
    protected function buildExpression($a, $b)
54
    {
55
        return new Node\Expr\BinaryOp\Spaceship($a, $b);
56
    }
57
}
58