Completed
Push — master ( 5f2691...53c2bd )
by Enrico
03:49
created

BaseTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A smallerDataProvider() 0 15 1
operator() 0 1 ?
buildExpression() 0 1 ?
A testSimpleSuccessCompile() 0 12 1
A testFirstUnexpectedTypes() 0 12 1
A testSecondUnexpectedTypes() 0 12 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Operators\Comparison;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
abstract class BaseTestCase extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function smallerDataProvider()
15
    {
16
        return array(
17
            array(-1, -1),
18
            array(-2, -1),
19
            array(-3, -1),
20
            array(-50, -1),
21
            array(1, 2),
22
            array(1, 5),
23
            array(6, 5),
24
            array(6, 6),
25
            array(5, 6),
26
            array(5, 5),
27
        );
28
    }
29
30
    /**
31
     * @param $a
32
     * @param $b
33
     * @return mixed
34
     */
35
    abstract protected function operator($a, $b);
36
37
    /**
38
     * @param \PhpParser\Node\Scalar $a
39
     * @param \PhpParser\Node\Scalar $b
40
     * @return \PhpParser\Node\Expr\BinaryOp
41
     */
42
    abstract protected function buildExpression($a, $b);
43
44
    /**
45
     * Tests {int} $operator {int} = {int}
46
     *
47
     * @dataProvider smallerDataProvider
48
     */
49
    public function testSimpleSuccessCompile($a, $b)
50
    {
51
        $baseExpression = $this->buildExpression(
52
            $this->newScalarExpr($a),
0 ignored issues
show
Bug introduced by
It seems like $this->newScalarExpr($a) targeting Tests\PHPSA\TestCase::newScalarExpr() can also be of type object<PhpParser\Node\Expr\Array_>; however, Tests\PHPSA\Compiler\Exp...Case::buildExpression() does only seem to accept object<PhpParser\Node\Scalar>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
53
            $this->newScalarExpr($b)
0 ignored issues
show
Bug introduced by
It seems like $this->newScalarExpr($b) targeting Tests\PHPSA\TestCase::newScalarExpr() can also be of type object<PhpParser\Node\Expr\Array_>; however, Tests\PHPSA\Compiler\Exp...Case::buildExpression() does only seem to accept object<PhpParser\Node\Scalar>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
54
        );
55
        $compiledExpression = $this->compileExpression($baseExpression);
56
57
        $this->assertInstanceOfCompiledExpression($compiledExpression);
58
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
59
        $this->assertSame($this->operator($a, $b), $compiledExpression->getValue());
60
    }
61
62
    public function testFirstUnexpectedTypes()
63
    {
64
        $baseExpression = $this->buildExpression(
65
            $this->newFakeScalarExpr(),
66
            $this->newScalarExpr(1)
0 ignored issues
show
Bug introduced by
It seems like $this->newScalarExpr(1) targeting Tests\PHPSA\TestCase::newScalarExpr() can also be of type object<PhpParser\Node\Expr\Array_>; however, Tests\PHPSA\Compiler\Exp...Case::buildExpression() does only seem to accept object<PhpParser\Node\Scalar>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
67
        );
68
        $compiledExpression = $this->compileExpression($baseExpression);
69
70
        $this->assertInstanceOfCompiledExpression($compiledExpression);
71
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
72
        $this->assertSame(null, $compiledExpression->getValue());
73
    }
74
75
    public function testSecondUnexpectedTypes()
76
    {
77
        $baseExpression = $this->buildExpression(
78
            $this->newScalarExpr(1),
0 ignored issues
show
Bug introduced by
It seems like $this->newScalarExpr(1) targeting Tests\PHPSA\TestCase::newScalarExpr() can also be of type object<PhpParser\Node\Expr\Array_>; however, Tests\PHPSA\Compiler\Exp...Case::buildExpression() does only seem to accept object<PhpParser\Node\Scalar>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
79
            $this->newFakeScalarExpr()
80
        );
81
        $compiledExpression = $this->compileExpression($baseExpression);
82
83
        $this->assertInstanceOfCompiledExpression($compiledExpression);
84
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
85
        $this->assertSame(null, $compiledExpression->getValue());
86
    }
87
}
88