Skip to content

Commit d7d7f92

Browse files
committed
expanded all tests with parentheses
1 parent fc32dde commit d7d7f92

20 files changed

+246
-53
lines changed

tests/Unit/AdditionTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,35 @@ class AdditionTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
39-
$addition = new Addition($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
39+
$left = $this->getQueryConvertableMock(NumeralType::class, "10");
40+
$right = $this->getQueryConvertableMock(NumeralType::class, "15");
41+
$addition = new Addition($left, $right);
4042

4143
$this->assertSame("(10 + 15)", $addition->toQuery());
4244

43-
$addition = new Addition($addition, $addition);
45+
$this->assertEquals($left, $addition->getLeft());
46+
$this->assertEquals($right, $addition->getRight());
4447

45-
$this->assertSame("((10 + 15) + (10 + 15))", $addition->toQuery());
48+
$newAddition = new Addition($addition, $addition);
49+
50+
$this->assertSame("((10 + 15) + (10 + 15))", $newAddition->toQuery());
51+
52+
$this->assertTrue($newAddition->insertsParentheses());
53+
$this->assertEquals($addition, $newAddition->getLeft());
54+
$this->assertEquals($addition, $newAddition->getRight());
55+
56+
$newAddition = new Addition($addition, $addition, false);
57+
58+
$this->assertSame("(10 + 15) + (10 + 15)", $newAddition->toQuery());
59+
60+
$this->assertFalse($newAddition->insertsParentheses());
61+
$this->assertEquals($addition, $newAddition->getLeft());
62+
$this->assertEquals($addition, $newAddition->getRight());
4663
}
4764

48-
public function testDoesNotAcceptAnyTypeAsOperands()
65+
public function testDoesNotAcceptAnyTypeAsOperands(): void
4966
{
5067
$this->expectException(TypeError::class);
5168

tests/Unit/AndOperatorTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AndOperatorTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$and = new AndOperator($this->getQueryConvertableMock(BooleanType::class, "true"), $this->getQueryConvertableMock(BooleanType::class, "false"));
4040

@@ -45,7 +45,18 @@ public function testToQuery()
4545
$this->assertSame("((true AND false) AND (true AND false))", $and->toQuery());
4646
}
4747

48-
public function testDoesNotAcceptAnyTypeAsOperands()
48+
public function testToQueryNoParentheses(): void
49+
{
50+
$and = new AndOperator($this->getQueryConvertableMock(BooleanType::class, "true"), $this->getQueryConvertableMock(BooleanType::class, "false"), false);
51+
52+
$this->assertSame("true AND false", $and->toQuery());
53+
54+
$and = new AndOperator($and, $and);
55+
56+
$this->assertSame("(true AND false AND true AND false)", $and->toQuery());
57+
}
58+
59+
public function testDoesNotAcceptAnyTypeAsOperands(): void
4960
{
5061
$this->expectException(TypeError::class);
5162

tests/Unit/ContainsTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class ContainsTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$contains = new Contains($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"));
4040

4141
$this->assertSame("(a CONTAINS b)", $contains->toQuery());
4242
}
4343

44-
public function testCannotBeNested()
44+
public function testToQueryNoParentheses(): void
45+
{
46+
$contains = new Contains($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"), false);
47+
48+
$this->assertSame("a CONTAINS b", $contains->toQuery());
49+
}
50+
51+
public function testCannotBeNested(): void
4552
{
4653
$contains = new Contains($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"));
4754

@@ -52,7 +59,7 @@ public function testCannotBeNested()
5259
$contains->toQuery();
5360
}
5461

55-
public function testDoesNotAcceptAnyTypeAsOperands()
62+
public function testDoesNotAcceptAnyTypeAsOperands(): void
5663
{
5764
$this->expectException(TypeError::class);
5865

tests/Unit/DivisionTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DivisionTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$division = new Division($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4040

@@ -45,7 +45,18 @@ public function testToQuery()
4545
$this->assertSame("((10 / 15) / (10 / 15))", $division->toQuery());
4646
}
4747

48-
public function testDoesNotAcceptAnyTypeAsOperands()
48+
public function testToQueryNoParentheses(): void
49+
{
50+
$division = new Division($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"), false);
51+
52+
$this->assertSame("10 / 15", $division->toQuery());
53+
54+
$division = new Division($division, $division);
55+
56+
$this->assertSame("(10 / 15 / 10 / 15)", $division->toQuery());
57+
}
58+
59+
public function testDoesNotAcceptAnyTypeAsOperands(): void
4960
{
5061
$this->expectException(TypeError::class);
5162

tests/Unit/EndsWithTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class EndsWithTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$endsWith = new EndsWith($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"));
4040

4141
$this->assertSame("(a ENDS WITH b)", $endsWith->toQuery());
4242
}
4343

44-
public function testCannotBeNested()
44+
public function testToQueryNoParentheses(): void
45+
{
46+
$endsWith = new EndsWith($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"), false);
47+
48+
$this->assertSame("a ENDS WITH b", $endsWith->toQuery());
49+
}
50+
51+
public function testCannotBeNested(): void
4552
{
4653
$endsWith = new EndsWith($this->getQueryConvertableMock(StringType::class, "a"), $this->getQueryConvertableMock(StringType::class, "b"));
4754

@@ -52,7 +59,7 @@ public function testCannotBeNested()
5259
$endsWith->toQuery();
5360
}
5461

55-
public function testDoesNotAcceptAnyTypeAsOperands()
62+
public function testDoesNotAcceptAnyTypeAsOperands(): void
5663
{
5764
$this->expectException(TypeError::class);
5865

tests/Unit/EqualityTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EqualityTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$equality = new Equality($this->getQueryConvertableMock(PropertyType::class, "10"), $this->getQueryConvertableMock(PropertyType::class, "15"));
4040

@@ -45,7 +45,18 @@ public function testToQuery()
4545
$this->assertSame("((10 = 15) = (10 = 15))", $equality->toQuery());
4646
}
4747

48-
public function testDoesNotAcceptAnyTypeAsOperands()
48+
public function testToQueryNoParentheses(): void
49+
{
50+
$equality = new Equality($this->getQueryConvertableMock(PropertyType::class, "10"), $this->getQueryConvertableMock(PropertyType::class, "15"), false);
51+
52+
$this->assertSame("10 = 15", $equality->toQuery());
53+
54+
$equality = new Equality($equality, $equality);
55+
56+
$this->assertSame("(10 = 15 = 10 = 15)", $equality->toQuery());
57+
}
58+
59+
public function testDoesNotAcceptAnyTypeAsOperands(): void
4960
{
5061
$this->expectException(TypeError::class);
5162

tests/Unit/ExponentiationTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ExponentiationTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$exponentiation = new Exponentiation($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4040

@@ -45,7 +45,18 @@ public function testToQuery()
4545
$this->assertSame("((10 ^ 15) ^ (10 ^ 15))", $exponentiation->toQuery());
4646
}
4747

48-
public function testDoesNotAcceptAnyTypeAsOperands()
48+
public function testToQueryNoParentheses(): void
49+
{
50+
$exponentiation = new Exponentiation($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"), false);
51+
52+
$this->assertSame("10 ^ 15", $exponentiation->toQuery());
53+
54+
$exponentiation = new Exponentiation($exponentiation, $exponentiation);
55+
56+
$this->assertSame("(10 ^ 15 ^ 10 ^ 15)", $exponentiation->toQuery());
57+
}
58+
59+
public function testDoesNotAcceptAnyTypeAsOperands(): void
4960
{
5061
$this->expectException(TypeError::class);
5162

tests/Unit/GreaterThanOrEqualTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class GreaterThanOrEqualTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$greaterThanOrEqual = new GreaterThanOrEqual($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4040

4141
$this->assertSame("(10 >= 15)", $greaterThanOrEqual->toQuery());
4242
}
4343

44-
public function testCannotBeNested()
44+
public function testToQueryNoParentheses(): void
45+
{
46+
$greaterThanOrEqual = new GreaterThanOrEqual($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"), false);
47+
48+
$this->assertSame("10 >= 15", $greaterThanOrEqual->toQuery());
49+
}
50+
51+
public function testCannotBeNested(): void
4552
{
4653
$greaterThanOrEqual = new GreaterThanOrEqual($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4754

@@ -52,7 +59,7 @@ public function testCannotBeNested()
5259
$greaterThanOrEqual->toQuery();
5360
}
5461

55-
public function testDoesNotAcceptAnyTypeAsOperands()
62+
public function testDoesNotAcceptAnyTypeAsOperands(): void
5663
{
5764
$this->expectException(TypeError::class);
5865

tests/Unit/GreaterThanTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class GreaterThanTest extends TestCase
3434
{
3535
use TestHelper;
3636

37-
public function testToQuery()
37+
public function testToQuery(): void
3838
{
3939
$greaterThan = new GreaterThan($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4040

4141
$this->assertSame("(10 > 15)", $greaterThan->toQuery());
4242
}
4343

44-
public function testCannotBeNested()
44+
public function testToQueryNoParentheses(): void
45+
{
46+
$greaterThan = new GreaterThan($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"), false);
47+
48+
$this->assertSame("10 > 15", $greaterThan->toQuery());
49+
}
50+
51+
public function testCannotBeNested(): void
4552
{
4653
$greaterThan = new GreaterThan($this->getQueryConvertableMock(NumeralType::class, "10"), $this->getQueryConvertableMock(NumeralType::class, "15"));
4754

@@ -52,7 +59,7 @@ public function testCannotBeNested()
5259
$greaterThan->toQuery();
5360
}
5461

55-
public function testDoesNotAcceptAnyTypeAsOperands()
62+
public function testDoesNotAcceptAnyTypeAsOperands(): void
5663
{
5764
$this->expectException(TypeError::class);
5865

tests/Unit/InTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class InTest extends TestCase
3737
{
3838
use TestHelper;
3939

40-
public function testToQuery()
40+
public function testToQuery(): void
4141
{
4242
$inequality = new In($this->getQueryConvertableMock(PropertyType::class, "a"), $this->getQueryConvertableMock(ListType::class, "b"));
4343

@@ -48,7 +48,18 @@ public function testToQuery()
4848
$this->assertSame("((a IN b) IN c)", $inequality->toQuery());
4949
}
5050

51-
public function testInExpressionList()
51+
public function testToQueryNoParentheses(): void
52+
{
53+
$inequality = new In($this->getQueryConvertableMock(PropertyType::class, "a"), $this->getQueryConvertableMock(ListType::class, "b"), false);
54+
55+
$this->assertSame("a IN b", $inequality->toQuery());
56+
57+
$inequality = new In($inequality, $this->getQueryConvertableMock(ListType::class, "c"));
58+
59+
$this->assertSame("(a IN b IN c)", $inequality->toQuery());
60+
}
61+
62+
public function testInExpressionList(): void
5263
{
5364
$inequality = new In($this->getQueryConvertableMock(PropertyType::class, "a"), new ExpressionList([new StringLiteral('a'), new StringLiteral('b')]));
5465

@@ -59,7 +70,7 @@ public function testInExpressionList()
5970
$this->assertSame("((a IN ['a', 'b']) IN c)", $inequality->toQuery());
6071
}
6172

62-
public function testDoesNotAcceptAnyTypeAsOperands()
73+
public function testDoesNotAcceptAnyTypeAsOperands(): void
6374
{
6475
$this->expectException(TypeError::class);
6576

0 commit comments

Comments
 (0)