Code Duplication    Length = 75-76 lines in 2 locations

eZ/Publish/Core/Persistence/Cache/Tests/UrlAliasHandlerTest.php 2 locations

@@ 457-532 (lines=76) @@
454
    /**
455
     * @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation
456
     */
457
    public function testListURLAliasesForLocationHasCache()
458
    {
459
        $this->loggerMock->expects($this->never())->method('logCall');
460
461
        $cacheItemMock = $this->getCacheItemMock();
462
        $this->cacheMock
463
            ->expects($this->at(0))
464
            ->method('getItem')
465
            ->with('urlAlias', 'location', 44)
466
            ->will($this->returnValue($cacheItemMock));
467
468
        $cacheItemMock
469
            ->expects($this->once())
470
            ->method('get')
471
            ->will($this->returnValue(array(55, 58, 91)));
472
473
        $cacheItemMock
474
            ->expects($this->once())
475
            ->method('isMiss')
476
            ->will($this->returnValue(false));
477
478
        $this->persistenceHandlerMock
479
            ->expects($this->never())
480
            ->method($this->anything());
481
482
        $cacheItemMock
483
            ->expects($this->never())
484
            ->method('set');
485
486
        // inline calls to loadUrlAlias() using the cache
487
        $cacheItemMock2 = $this->getCacheItemMock();
488
        $this->cacheMock
489
            ->expects($this->at(1))
490
            ->method('getItem')
491
            ->with('urlAlias', 55)
492
            ->will($this->returnValue($cacheItemMock2));
493
494
        $cacheItemMock2
495
            ->expects($this->at(0))
496
            ->method('get')
497
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
498
499
        $this->cacheMock
500
            ->expects($this->at(2))
501
            ->method('getItem')
502
            ->with('urlAlias', 58)
503
            ->will($this->returnValue($cacheItemMock2));
504
505
        $cacheItemMock2
506
            ->expects($this->at(1))
507
            ->method('get')
508
            ->will($this->returnValue(new UrlAlias(array('id' => 58))));
509
510
        $this->cacheMock
511
            ->expects($this->at(3))
512
            ->method('getItem')
513
            ->with('urlAlias', 91)
514
            ->will($this->returnValue($cacheItemMock2));
515
516
        $cacheItemMock2
517
            ->expects($this->at(2))
518
            ->method('get')
519
            ->will($this->returnValue(new UrlAlias(array('id' => 91))));
520
521
        $cacheItemMock2
522
            ->expects($this->exactly(3))
523
            ->method('isMiss')
524
            ->will($this->returnValue(false));
525
526
        $cacheItemMock2
527
            ->expects($this->never())
528
            ->method('set');
529
530
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
531
        $handler->listURLAliasesForLocation(44, false);
532
    }
533
534
    /**
535
     * @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation
@@ 537-611 (lines=75) @@
534
    /**
535
     * @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation
536
     */
537
    public function testListURLAliasesForLocationCustomHasCache()
538
    {
539
        $this->loggerMock->expects($this->never())->method('logCall');
540
541
        $cacheItemMock = $this->getCacheItemMock();
542
        $this->cacheMock
543
            ->expects($this->at(0))
544
            ->method('getItem')
545
            ->with('urlAlias', 'location', '44', 'custom')
546
            ->will($this->returnValue($cacheItemMock));
547
548
        $cacheItemMock
549
            ->expects($this->once())
550
            ->method('get')
551
            ->will($this->returnValue(array(55, 58, 91)));
552
553
        $cacheItemMock
554
            ->expects($this->once())
555
            ->method('isMiss')
556
            ->will($this->returnValue(false));
557
558
        $this->persistenceHandlerMock
559
            ->expects($this->never())
560
            ->method($this->anything());
561
562
        $cacheItemMock
563
            ->expects($this->never())
564
            ->method('set');
565
566
        $cacheItemMock2 = $this->getCacheItemMock();
567
        $this->cacheMock
568
            ->expects($this->at(1))
569
            ->method('getItem')
570
            ->with('urlAlias', 55)
571
            ->will($this->returnValue($cacheItemMock2));
572
573
        $cacheItemMock2
574
            ->expects($this->at(0))
575
            ->method('get')
576
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
577
578
        $this->cacheMock
579
            ->expects($this->at(2))
580
            ->method('getItem')
581
            ->with('urlAlias', 58)
582
            ->will($this->returnValue($cacheItemMock2));
583
584
        $cacheItemMock2
585
            ->expects($this->at(1))
586
            ->method('get')
587
            ->will($this->returnValue(new UrlAlias(array('id' => 58))));
588
589
        $this->cacheMock
590
            ->expects($this->at(3))
591
            ->method('getItem')
592
            ->with('urlAlias', 91)
593
            ->will($this->returnValue($cacheItemMock2));
594
595
        $cacheItemMock2
596
            ->expects($this->at(2))
597
            ->method('get')
598
            ->will($this->returnValue(new UrlAlias(array('id' => 91))));
599
600
        $cacheItemMock2
601
            ->expects($this->exactly(3))
602
            ->method('isMiss')
603
            ->will($this->returnValue(false));
604
605
        $cacheItemMock2
606
            ->expects($this->never())
607
            ->method('set');
608
609
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
610
        $handler->listURLAliasesForLocation(44, true);
611
    }
612
613
    /**
614
     * @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::removeURLAliases