35
35
use WikibaseSolutions \CypherDSL \Multiplication ;
36
36
use WikibaseSolutions \CypherDSL \Subtraction ;
37
37
use WikibaseSolutions \CypherDSL \Tests \Unit \TestHelper ;
38
+ use WikibaseSolutions \CypherDSL \Traits \NumeralTypeTrait ;
38
39
use WikibaseSolutions \CypherDSL \Types \PropertyTypes \NumeralType ;
39
40
40
41
/**
@@ -56,81 +57,238 @@ class NumeralTypeTraitTest extends TestCase
56
57
57
58
public function setUp (): void
58
59
{
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
+ };
60
68
$ this ->b = $ this ->getQueryConvertableMock (NumeralType::class, "15 " );
61
69
}
62
70
63
- public function testPlus ()
71
+ public function testPlus (): void
64
72
{
65
73
$ plus = $ this ->a ->plus ($ this ->b );
66
74
67
75
$ 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 ());
68
80
}
69
81
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
71
94
{
72
95
$ divide = $ this ->a ->divide ($ this ->b );
73
96
74
97
$ 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 ());
75
113
}
76
114
77
- public function testExponentiate ()
115
+ public function testExponentiate (): void
78
116
{
79
117
$ exponentiate = $ this ->a ->exponentiate ($ this ->b );
80
118
81
119
$ 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 ());
82
135
}
83
136
84
- public function testGt ()
137
+ public function testGt (): void
85
138
{
86
139
$ gt = $ this ->a ->gt ($ this ->b );
87
140
88
141
$ 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 ());
89
157
}
90
158
91
- public function testGte ()
159
+ public function testGte (): void
92
160
{
93
161
$ gte = $ this ->a ->gte ($ this ->b );
94
162
95
163
$ 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 ());
96
179
}
97
180
98
- public function testLt ()
181
+ public function testLt (): void
99
182
{
100
183
$ lt = $ this ->a ->lt ($ this ->b );
101
184
102
185
$ 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 ());
103
190
}
104
191
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
106
204
{
107
205
$ lte = $ this ->a ->lte ($ this ->b );
108
206
109
207
$ 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 ());
110
223
}
111
224
112
- public function testMod ()
225
+ public function testMod (): void
113
226
{
114
227
$ mod = $ this ->a ->mod ($ this ->b );
115
228
116
229
$ 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 ());
117
234
}
118
235
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
120
248
{
121
249
$ times = $ this ->a ->times ($ this ->b );
122
250
123
251
$ 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 ());
124
256
}
125
257
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
127
270
{
128
271
$ minus = $ this ->a ->minus ($ this ->b );
129
272
130
273
$ 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 ());
131
289
}
132
290
133
- public function testNegate ()
291
+ public function testNegate (): void
134
292
{
135
293
$ negate = $ this ->a ->negate ();
136
294
0 commit comments