Skip to content

Commit fc32dde

Browse files
committed
expanded Trait tests
1 parent 8d5815d commit fc32dde

File tree

5 files changed

+359
-27
lines changed

5 files changed

+359
-27
lines changed

src/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Regex extends BinaryOperator implements BooleanType
3939
*/
4040
public function __construct(StringType $left, StringType $right, bool $insertParentheses = true)
4141
{
42-
parent::__construct($left, $right);
42+
parent::__construct($left, $right, $insertParentheses);
4343
}
4444

4545
/**

tests/Unit/Traits/BooleanTypeTraitTest.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use WikibaseSolutions\CypherDSL\Not;
2828
use WikibaseSolutions\CypherDSL\OrOperator;
2929
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
30+
use WikibaseSolutions\CypherDSL\Traits\BooleanTypeTrait;
3031
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
3132
use WikibaseSolutions\CypherDSL\XorOperator;
3233

@@ -49,32 +50,84 @@ class BooleanTypeTraitTest extends TestCase
4950

5051
public function setUp(): void
5152
{
52-
$this->a = $this->getQueryConvertableMock(BooleanType::class, "true");
53+
$this->a = new class implements BooleanType {
54+
use BooleanTypeTrait;
55+
56+
public function toQuery(): string
57+
{
58+
return '';
59+
}
60+
};
5361
$this->b = $this->getQueryConvertableMock(BooleanType::class, "false");
5462
}
5563

56-
public function testAnd()
64+
public function testAnd(): void
5765
{
5866
$and = $this->a->and($this->b);
5967

6068
$this->assertInstanceOf(AndOperator::class, $and);
69+
70+
$this->assertTrue($and->insertsParentheses());
71+
$this->assertEquals($this->a, $and->getLeft());
72+
$this->assertEquals($this->b, $and->getRight());
6173
}
6274

63-
public function testOr()
75+
public function testAndNoParentheses(): void
76+
{
77+
$and = $this->a->and($this->b, false);
78+
79+
$this->assertInstanceOf(AndOperator::class, $and);
80+
81+
$this->assertFalse($and->insertsParentheses());
82+
$this->assertEquals($this->a, $and->getLeft());
83+
$this->assertEquals($this->b, $and->getRight());
84+
}
85+
86+
public function testOr(): void
6487
{
6588
$or = $this->a->or($this->b);
6689

6790
$this->assertInstanceOf(OrOperator::class, $or);
91+
92+
$this->assertTrue($or->insertsParentheses());
93+
$this->assertEquals($this->a, $or->getLeft());
94+
$this->assertEquals($this->b, $or->getRight());
95+
}
96+
97+
public function testOrNoParentheses(): void
98+
{
99+
$or = $this->a->or($this->b, false);
100+
101+
$this->assertInstanceOf(OrOperator::class, $or);
102+
103+
$this->assertFalse($or->insertsParentheses());
104+
$this->assertEquals($this->a, $or->getLeft());
105+
$this->assertEquals($this->b, $or->getRight());
68106
}
69107

70-
public function testXor()
108+
public function testXor(): void
71109
{
72110
$xor = $this->a->xor($this->b);
73111

74112
$this->assertInstanceOf(XorOperator::class, $xor);
113+
114+
$this->assertTrue($xor->insertsParentheses());
115+
$this->assertEquals($this->a, $xor->getLeft());
116+
$this->assertEquals($this->b, $xor->getRight());
117+
}
118+
119+
public function testXorNoParentheses(): void
120+
{
121+
$xor = $this->a->xor($this->b, false);
122+
123+
$this->assertInstanceOf(XorOperator::class, $xor);
124+
125+
$this->assertFalse($xor->insertsParentheses());
126+
$this->assertEquals($this->a, $xor->getLeft());
127+
$this->assertEquals($this->b, $xor->getRight());
75128
}
76129

77-
public function testNot()
130+
public function testNot(): void
78131
{
79132
$not = $this->a->not();
80133

tests/Unit/Traits/NumeralTypeTraitTest.php

Lines changed: 170 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use WikibaseSolutions\CypherDSL\Multiplication;
3636
use WikibaseSolutions\CypherDSL\Subtraction;
3737
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
38+
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
3839
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
3940

4041
/**
@@ -56,81 +57,238 @@ class NumeralTypeTraitTest extends TestCase
5657

5758
public function setUp(): void
5859
{
59-
$this->a = $this->getQueryConvertableMock(NumeralType::class, "10");
60+
$this->a = new class implements NumeralType {
61+
use NumeralTypeTrait;
62+
63+
public function toQuery(): string
64+
{
65+
return '10';
66+
}
67+
};
6068
$this->b = $this->getQueryConvertableMock(NumeralType::class, "15");
6169
}
6270

63-
public function testPlus()
71+
public function testPlus(): void
6472
{
6573
$plus = $this->a->plus($this->b);
6674

6775
$this->assertInstanceOf(Addition::class, $plus);
76+
77+
$this->assertTrue($plus->insertsParentheses());
78+
$this->assertEquals($this->a, $plus->getLeft());
79+
$this->assertEquals($this->b, $plus->getRight());
6880
}
6981

70-
public function testDivide()
82+
public function testPlusNoParentheses(): void
83+
{
84+
$plus = $this->a->plus($this->b, false);
85+
86+
$this->assertInstanceOf(Addition::class, $plus);
87+
88+
$this->assertFalse($plus->insertsParentheses());
89+
$this->assertEquals($this->a, $plus->getLeft());
90+
$this->assertEquals($this->b, $plus->getRight());
91+
}
92+
93+
public function testDivide(): void
7194
{
7295
$divide = $this->a->divide($this->b);
7396

7497
$this->assertInstanceOf(Division::class, $divide);
98+
99+
$this->assertTrue($divide->insertsParentheses());
100+
$this->assertEquals($this->a, $divide->getLeft());
101+
$this->assertEquals($this->b, $divide->getRight());
102+
}
103+
104+
public function testDivideNoParentheses(): void
105+
{
106+
$divide = $this->a->divide($this->b, false);
107+
108+
$this->assertInstanceOf(Division::class, $divide);
109+
110+
$this->assertFalse($divide->insertsParentheses());
111+
$this->assertEquals($this->a, $divide->getLeft());
112+
$this->assertEquals($this->b, $divide->getRight());
75113
}
76114

77-
public function testExponentiate()
115+
public function testExponentiate(): void
78116
{
79117
$exponentiate = $this->a->exponentiate($this->b);
80118

81119
$this->assertInstanceOf(Exponentiation::class, $exponentiate);
120+
121+
$this->assertTrue($exponentiate->insertsParentheses());
122+
$this->assertEquals($this->a, $exponentiate->getLeft());
123+
$this->assertEquals($this->b, $exponentiate->getRight());
124+
}
125+
126+
public function testExponentiateNoParentheses(): void
127+
{
128+
$exponentiate = $this->a->exponentiate($this->b, false);
129+
130+
$this->assertInstanceOf(Exponentiation::class, $exponentiate);
131+
132+
$this->assertFalse($exponentiate->insertsParentheses());
133+
$this->assertEquals($this->a, $exponentiate->getLeft());
134+
$this->assertEquals($this->b, $exponentiate->getRight());
82135
}
83136

84-
public function testGt()
137+
public function testGt(): void
85138
{
86139
$gt = $this->a->gt($this->b);
87140

88141
$this->assertInstanceOf(GreaterThan::class, $gt);
142+
143+
$this->assertTrue($gt->insertsParentheses());
144+
$this->assertEquals($this->a, $gt->getLeft());
145+
$this->assertEquals($this->b, $gt->getRight());
146+
}
147+
148+
public function testGtNoParentheses(): void
149+
{
150+
$gt = $this->a->gt($this->b, false);
151+
152+
$this->assertInstanceOf(GreaterThan::class, $gt);
153+
154+
$this->assertFalse($gt->insertsParentheses());
155+
$this->assertEquals($this->a, $gt->getLeft());
156+
$this->assertEquals($this->b, $gt->getRight());
89157
}
90158

91-
public function testGte()
159+
public function testGte(): void
92160
{
93161
$gte = $this->a->gte($this->b);
94162

95163
$this->assertInstanceOf(GreaterThanOrEqual::class, $gte);
164+
165+
$this->assertTrue($gte->insertsParentheses());
166+
$this->assertEquals($this->a, $gte->getLeft());
167+
$this->assertEquals($this->b, $gte->getRight());
168+
}
169+
170+
public function testGteNoParentheses(): void
171+
{
172+
$gte = $this->a->gte($this->b, false);
173+
174+
$this->assertInstanceOf(GreaterThanOrEqual::class, $gte);
175+
176+
$this->assertFalse($gte->insertsParentheses());
177+
$this->assertEquals($this->a, $gte->getLeft());
178+
$this->assertEquals($this->b, $gte->getRight());
96179
}
97180

98-
public function testLt()
181+
public function testLt(): void
99182
{
100183
$lt = $this->a->lt($this->b);
101184

102185
$this->assertInstanceOf(LessThan::class, $lt);
186+
187+
$this->assertTrue($lt->insertsParentheses());
188+
$this->assertEquals($this->a, $lt->getLeft());
189+
$this->assertEquals($this->b, $lt->getRight());
103190
}
104191

105-
public function testLte()
192+
public function testLtNoParentheses(): void
193+
{
194+
$lt = $this->a->lt($this->b, false);
195+
196+
$this->assertInstanceOf(LessThan::class, $lt);
197+
198+
$this->assertFalse($lt->insertsParentheses());
199+
$this->assertEquals($this->a, $lt->getLeft());
200+
$this->assertEquals($this->b, $lt->getRight());
201+
}
202+
203+
public function testLte(): void
106204
{
107205
$lte = $this->a->lte($this->b);
108206

109207
$this->assertInstanceOf(LessThanOrEqual::class, $lte);
208+
209+
$this->assertTrue($lte->insertsParentheses());
210+
$this->assertEquals($this->a, $lte->getLeft());
211+
$this->assertEquals($this->b, $lte->getRight());
212+
}
213+
214+
public function testLteNoParentheses(): void
215+
{
216+
$lte = $this->a->lte($this->b, false);
217+
218+
$this->assertInstanceOf(LessThanOrEqual::class, $lte);
219+
220+
$this->assertFalse($lte->insertsParentheses());
221+
$this->assertEquals($this->a, $lte->getLeft());
222+
$this->assertEquals($this->b, $lte->getRight());
110223
}
111224

112-
public function testMod()
225+
public function testMod(): void
113226
{
114227
$mod = $this->a->mod($this->b);
115228

116229
$this->assertInstanceOf(Modulo::class, $mod);
230+
231+
$this->assertTrue($mod->insertsParentheses());
232+
$this->assertEquals($this->a, $mod->getLeft());
233+
$this->assertEquals($this->b, $mod->getRight());
117234
}
118235

119-
public function testTimes()
236+
public function testModNoParentheses(): void
237+
{
238+
$mod = $this->a->mod($this->b, false);
239+
240+
$this->assertInstanceOf(Modulo::class, $mod);
241+
242+
$this->assertFalse($mod->insertsParentheses());
243+
$this->assertEquals($this->a, $mod->getLeft());
244+
$this->assertEquals($this->b, $mod->getRight());
245+
}
246+
247+
public function testTimes(): void
120248
{
121249
$times = $this->a->times($this->b);
122250

123251
$this->assertInstanceOf(Multiplication::class, $times);
252+
253+
$this->assertTrue($times->insertsParentheses());
254+
$this->assertEquals($this->a, $times->getLeft());
255+
$this->assertEquals($this->b, $times->getRight());
124256
}
125257

126-
public function testMinus()
258+
public function testTimesNoParentheses(): void
259+
{
260+
$times = $this->a->times($this->b, false);
261+
262+
$this->assertInstanceOf(Multiplication::class, $times);
263+
264+
$this->assertFalse($times->insertsParentheses());
265+
$this->assertEquals($this->a, $times->getLeft());
266+
$this->assertEquals($this->b, $times->getRight());
267+
}
268+
269+
public function testMinus(): void
127270
{
128271
$minus = $this->a->minus($this->b);
129272

130273
$this->assertInstanceOf(Subtraction::class, $minus);
274+
275+
$this->assertTrue($minus->insertsParentheses());
276+
$this->assertEquals($this->a, $minus->getLeft());
277+
$this->assertEquals($this->b, $minus->getRight());
278+
}
279+
280+
public function testMinusNoParentheses(): void
281+
{
282+
$minus = $this->a->minus($this->b, false);
283+
284+
$this->assertInstanceOf(Subtraction::class, $minus);
285+
286+
$this->assertFalse($minus->insertsParentheses());
287+
$this->assertEquals($this->a, $minus->getLeft());
288+
$this->assertEquals($this->b, $minus->getRight());
131289
}
132290

133-
public function testNegate()
291+
public function testNegate(): void
134292
{
135293
$negate = $this->a->negate();
136294

0 commit comments

Comments
 (0)