21
21
22
22
namespace WikibaseSolutions \CypherDSL \Tests \Unit \Patterns ;
23
23
24
+ use DomainException ;
25
+ use LogicException ;
24
26
use PHPUnit \Framework \MockObject \MockObject ;
25
27
use PHPUnit \Framework \TestCase ;
26
28
use WikibaseSolutions \CypherDSL \Literals \Decimal ;
27
29
use WikibaseSolutions \CypherDSL \Literals \StringLiteral ;
28
30
use WikibaseSolutions \CypherDSL \Patterns \Node ;
29
31
use WikibaseSolutions \CypherDSL \Patterns \Path ;
32
+ use WikibaseSolutions \CypherDSL \Query ;
30
33
use WikibaseSolutions \CypherDSL \Tests \Unit \TestHelper ;
31
34
use WikibaseSolutions \CypherDSL \Types \StructuralTypes \StructuralType ;
32
35
@@ -271,6 +274,8 @@ public function testVariableLengthRelationshipsWithProperties(array $properties,
271
274
* @param string $name
272
275
* @param string $type
273
276
* @param array $properties
277
+ * @param int|null $minHops
278
+ * @param int|null $maxHops
274
279
* @param array $direction
275
280
* @param string $expected
276
281
*/
@@ -290,11 +295,148 @@ public function testVariableLengthRelationshipsWithNameAndTypeAndProperties(stri
290
295
$ this ->assertSame ($ expected , $ r ->toQuery ());
291
296
}
292
297
298
+ public function testExactLengthRelationships ()
299
+ {
300
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
301
+ $ r ->named ("tom " )
302
+ ->withType ("Person " )
303
+ ->withProperties (['name ' => Query::literal ('Tom Hanks ' )]);
304
+
305
+ $ r ->withExactHops (10 );
306
+
307
+ $ this ->assertSame ("(a)-[tom:Person*10 {name: 'Tom Hanks'}]->(b) " , $ r ->toQuery ());
308
+ }
309
+
310
+ public function testMinAndExactHops ()
311
+ {
312
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
313
+ $ r ->withMinHops (1 );
314
+
315
+ $ this ->expectException (LogicException::class);
316
+
317
+ $ r ->withExactHops (1 );
318
+ }
319
+
320
+ public function testMaxAndExactHops ()
321
+ {
322
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
323
+ $ r ->withMaxHops (1 );
324
+
325
+ $ this ->expectException (LogicException::class);
326
+
327
+ $ r ->withExactHops (1 );
328
+ }
329
+
330
+ public function testMinMaxAndExactHops ()
331
+ {
332
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
333
+ $ r ->withMinHops (1 );
334
+ $ r ->withMaxHops (1 );
335
+
336
+ $ this ->expectException (LogicException::class);
337
+
338
+ $ r ->withExactHops (1 );
339
+ }
340
+
341
+ public function testExactAndMinHops ()
342
+ {
343
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
344
+ $ r ->withExactHops (1 );
345
+
346
+ $ this ->expectException (LogicException::class);
347
+
348
+ $ r ->withMinHops (1 );
349
+ }
350
+
351
+ public function testExactAndMaxHops ()
352
+ {
353
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
354
+ $ r ->withExactHops (1 );
355
+
356
+ $ this ->expectException (LogicException::class);
357
+
358
+ $ r ->withMaxHops (1 );
359
+ }
360
+
361
+ public function testMaxHopsLessThanMinHops ()
362
+ {
363
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
364
+ $ r ->withMinHops (100 );
365
+
366
+ $ this ->expectException (DomainException::class);
367
+
368
+ $ r ->withMaxHops (1 );
369
+ }
370
+
371
+ public function testMinHopsGreaterThanMaxHops ()
372
+ {
373
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
374
+ $ r ->withMaxHops (1 );
375
+
376
+ $ this ->expectException (DomainException::class);
377
+
378
+ $ r ->withMinHops (100 );
379
+ }
380
+
381
+ public function testMinHopsLessThanOne ()
382
+ {
383
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
384
+
385
+ $ this ->expectException (DomainException::class);
386
+
387
+ $ r ->withMinHops (0 );
388
+ }
389
+
390
+ public function testMinHopsLessThanZero ()
391
+ {
392
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
393
+
394
+ $ this ->expectException (DomainException::class);
395
+
396
+ $ r ->withMinHops (-1 );
397
+ }
398
+
399
+ public function testMaxHopsLessThanOne ()
400
+ {
401
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
402
+
403
+ $ this ->expectException (DomainException::class);
404
+
405
+ $ r ->withMaxHops (0 );
406
+ }
407
+
408
+ public function testMaxHopsLessThanZero ()
409
+ {
410
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
411
+
412
+ $ this ->expectException (DomainException::class);
413
+
414
+ $ r ->withMaxHops (-1 );
415
+ }
416
+
417
+ public function testExactHopsLessThanOne ()
418
+ {
419
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
420
+
421
+ $ this ->expectException (DomainException::class);
422
+
423
+ $ r ->withExactHops (0 );
424
+ }
425
+
426
+ public function testExactHopsLessThanZero ()
427
+ {
428
+ $ r = new Path ($ this ->a , $ this ->b , Path::DIR_RIGHT );
429
+
430
+ $ this ->expectException (DomainException::class);
431
+
432
+ $ r ->withExactHops (-1 );
433
+ }
434
+
293
435
public function provideVariableLengthRelationshipsWithNameData (): array
294
436
{
295
437
return [
296
438
['' , 1 , 100 , Path::DIR_UNI , '(a)-[*1..100]-(b) ' ],
297
- ['a ' , 10 , null , Path::DIR_UNI , '(a)-[a*10]-(b) ' ],
439
+ ['a ' , 10 , null , Path::DIR_UNI , '(a)-[a*10.. ]-(b) ' ],
298
440
['a ' , null , 10 , Path::DIR_LEFT , '(a)<-[a*..10]-(b) ' ],
299
441
];
300
442
}
@@ -303,7 +445,7 @@ public function provideVariableLengthRelationshipsWithTypeData(): array
303
445
{
304
446
return [
305
447
['' , 1 , 100 , Path::DIR_LEFT , '(a)<-[*1..100]-(b) ' ],
306
- ['a ' , 10 , null , Path::DIR_LEFT , '(a)<-[:a*10]-(b) ' ],
448
+ ['a ' , 10 , null , Path::DIR_LEFT , '(a)<-[:a*10.. ]-(b) ' ],
307
449
[': ' , null , 10 , Path::DIR_LEFT , '(a)<-[:`:`*..10]-(b) ' ]
308
450
];
309
451
}
@@ -312,7 +454,7 @@ public function provideVariableLengthRelationshipsWithPropertiesData(): array
312
454
{
313
455
return [
314
456
[[], 10 , 100 , Path::DIR_LEFT , "(a)<-[*10..100 {}]-(b) " ],
315
- [[new StringLiteral ('a ' )], 10 , null , Path::DIR_LEFT , "(a)<-[*10 {`0`: 'a'}]-(b) " ],
457
+ [[new StringLiteral ('a ' )], 10 , null , Path::DIR_LEFT , "(a)<-[*10.. {`0`: 'a'}]-(b) " ],
316
458
[['a ' => new StringLiteral ('b ' )], null , 10 , Path::DIR_LEFT , "(a)<-[*..10 {a: 'b'}]-(b) " ]
317
459
];
318
460
}
@@ -322,11 +464,11 @@ public function provideVariableLengthRelationshipsWithNameAndTypeAndPropertiesDa
322
464
return [
323
465
['a ' , 'a ' , [], 10 , 100 , Path::DIR_LEFT , "(a)<-[a:a*10..100 {}]-(b) " ],
324
466
['b ' , 'a ' , [new StringLiteral ('a ' )], null , 10 , Path::DIR_LEFT , "(a)<-[b:a*..10 {`0`: 'a'}]-(b) " ],
325
- ['' , 'a ' , ['a ' => new StringLiteral ('b ' )], 10 , null , Path::DIR_LEFT , "(a)<-[:a*10 {a: 'b'}]-(b) " ],
467
+ ['' , 'a ' , ['a ' => new StringLiteral ('b ' )], 10 , null , Path::DIR_LEFT , "(a)<-[:a*10.. {a: 'b'}]-(b) " ],
326
468
[': ' , 'a ' , ['a ' => new StringLiteral ('b ' ), new StringLiteral ('c ' )], null , null , Path::DIR_LEFT , "(a)<-[`:`:a {a: 'b', `0`: 'c'}]-(b) " ],
327
469
['a ' , 'b ' , [new StringLiteral ('a ' )], 10 , 100 , Path::DIR_LEFT , "(a)<-[a:b*10..100 {`0`: 'a'}]-(b) " ],
328
470
['a ' , '' , ['a ' => new StringLiteral ('b ' )], null , 10 , Path::DIR_LEFT , "(a)<-[a*..10 {a: 'b'}]-(b) " ],
329
- ['a ' , ': ' , ['a ' => new StringLiteral ('b ' ), new StringLiteral ('c ' )], 10 , null , Path::DIR_LEFT , "(a)<-[a:`:`*10 {a: 'b', `0`: 'c'}]-(b) " ]
471
+ ['a ' , ': ' , ['a ' => new StringLiteral ('b ' ), new StringLiteral ('c ' )], 10 , null , Path::DIR_LEFT , "(a)<-[a:`:`*10.. {a: 'b', `0`: 'c'}]-(b) " ]
330
472
];
331
473
}
332
474
0 commit comments