-
-
Notifications
You must be signed in to change notification settings - Fork 336
/
BinaryOpConditionsCollectorTest.php
101 lines (78 loc) · 2.67 KB
/
BinaryOpConditionsCollectorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
declare(strict_types=1);
namespace Rector\Tests\NodeCollector;
use PhpParser\Node\Expr\BinaryOp\Minus;
use PhpParser\Node\Expr\BinaryOp\Plus;
use PhpParser\Node\Expr\Variable;
use PHPUnit\Framework\TestCase;
use Rector\NodeCollector\BinaryOpConditionsCollector;
final class BinaryOpConditionsCollectorTest extends TestCase
{
public function testLeftAssociative(): void
{
$binaryOpConditionsCollector = new BinaryOpConditionsCollector();
// (Plus (Plus a b) c)
$a = new Variable('a');
$b = new Variable('b');
$c = new Variable('c');
$abcPlus = new Plus(new Plus($a, $b), $c);
$result = $binaryOpConditionsCollector->findConditions($abcPlus, Plus::class);
$this->assertSame([
2 => $a,
1 => $b,
0 => $c,
], $result);
}
public function testRightAssociative(): void
{
$binaryOpConditionsCollector = new BinaryOpConditionsCollector();
// (Plus a (Plus b c))
$a = new Variable('a');
$b = new Variable('b');
$c = new Variable('c');
$bcPlus = new Plus($b, $c);
$abcPlus = new Plus($a, $bcPlus);
$result = $binaryOpConditionsCollector->findConditions($abcPlus, Plus::class);
$this->assertSame([
1 => $a,
0 => $bcPlus,
], $result);
}
public function testWrongRootOp(): void
{
$binaryOpConditionsCollector = new BinaryOpConditionsCollector();
// (Minus (Plus a b) c)
$a = new Variable('a');
$b = new Variable('b');
$c = new Variable('c');
$abcMinus = new Minus(new Plus($a, $b), $c);
$result = $binaryOpConditionsCollector->findConditions($abcMinus, Plus::class);
$this->assertSame([
0 => $abcMinus,
], $result);
}
public function testTrivialCase(): void
{
$binaryOpConditionsCollector = new BinaryOpConditionsCollector();
$variable = new Variable('a');
$result = $binaryOpConditionsCollector->findConditions($variable, Plus::class);
$this->assertSame([
0 => $variable,
], $result);
}
public function testInnerNodeDifferentOp(): void
{
$binaryOpConditionsCollector = new BinaryOpConditionsCollector();
// (Plus (Minus a b) c)
$a = new Variable('a');
$b = new Variable('b');
$c = new Variable('c');
$abMinus = new Minus($a, $b);
$abcPlus = new Plus($abMinus, $c);
$result = $binaryOpConditionsCollector->findConditions($abcPlus, Plus::class);
$this->assertSame([
1 => $abMinus,
0 => $c,
], $result);
}
}