Completed
Push — 6.7 ( ec4621...8ad775 )
by André
17:03
created

testCreateThrowsUnauthorizedException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\UrlWildcardTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\Tests\Service\Mock;
10
11
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest;
12
use eZ\Publish\API\Repository\Values\Content\URLWildcard;
13
use eZ\Publish\SPI\Persistence\Content\UrlWildcard as SPIURLWildcard;
14
use eZ\Publish\API\Repository\Values\Content\URLWildcardTranslationResult;
15
16
/**
17
 * Mock Test case for UrlWildcard Service.
18
 */
19
class UrlWildcardTest extends BaseServiceMockTest
20
{
21
    /**
22
     * Test for the __construct() method.
23
     *
24
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::__construct
25
     */
26
    public function testConstructor()
27
    {
28
        $service = $this->getPartlyMockedURLWildcardService();
29
30
        self::assertAttributeSame($this->getRepositoryMock(), 'repository', $service);
31
        self::assertAttributeSame($this->getPersistenceMockHandler('Content\\UrlWildcard\\Handler'), 'urlWildcardHandler', $service);
32
        self::assertAttributeSame(array(), 'settings', $service);
33
    }
34
35
    /**
36
     * Test for the create() method.
37
     *
38
     * @depends testConstructor
39
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::create
40
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
41
     */
42
    public function testCreateThrowsUnauthorizedException()
43
    {
44
        $mockedService = $this->getPartlyMockedURLWildcardService();
45
        $repositoryMock = $this->getRepositoryMock();
46
        $repositoryMock->expects(
47
            $this->once()
48
        )->method(
49
            'hasAccess'
50
        )->with(
51
            $this->equalTo('content'),
52
            $this->equalTo('urltranslator')
53
        )->will(
54
            $this->returnValue(false)
55
        );
56
57
        $mockedService->create('lorem/ipsum', 'opossum', true);
58
    }
59
60
    /**
61
     * Test for the create() method.
62
     *
63
     * @depends testConstructor
64
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::create
65
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
66
     */
67
    public function testCreateThrowsInvalidArgumentException()
68
    {
69
        $mockedService = $this->getPartlyMockedURLWildcardService();
70
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
71
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
72
        $repositoryMock = $this->getRepositoryMock();
73
74
        $repositoryMock->expects(
75
            $this->once()
76
        )->method(
77
            'hasAccess'
78
        )->with(
79
            $this->equalTo('content'),
80
            $this->equalTo('urltranslator')
81
        )->will(
82
            $this->returnValue(true)
83
        );
84
85
        $handlerMock->expects(
86
            $this->once()
87
        )->method(
88
            'loadAll'
89
        )->will(
90
            $this->returnValue(
91
                array(
92
                    new SPIURLWildcard(array('sourceUrl' => '/lorem/ipsum')),
93
                )
94
            )
95
        );
96
97
        $mockedService->create('/lorem/ipsum', 'opossum', true);
98
    }
99
100
    public function providerForTestCreateThrowsContentValidationException()
101
    {
102
        return array(
103
            array('fruit', 'food/{1}', true),
104
            array('fruit/*', 'food/{2}', false),
105
            array('fruit/*/*', 'food/{3}', true),
106
        );
107
    }
108
109
    /**
110
     * Test for the create() method.
111
     *
112
     * @depends testConstructor
113
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::create
114
     * @dataProvider providerForTestCreateThrowsContentValidationException
115
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException
116
     */
117
    public function testCreateThrowsContentValidationException($sourceUrl, $destinationUrl, $forward)
118
    {
119
        $mockedService = $this->getPartlyMockedURLWildcardService();
120
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
121
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
122
        $repositoryMock = $this->getRepositoryMock();
123
124
        $repositoryMock->expects(
125
            $this->once()
126
        )->method(
127
            'hasAccess'
128
        )->with(
129
            $this->equalTo('content'),
130
            $this->equalTo('urltranslator')
131
        )->will(
132
            $this->returnValue(true)
133
        );
134
135
        $handlerMock->expects(
136
            $this->once()
137
        )->method(
138
            'loadAll'
139
        )->will(
140
            $this->returnValue(array())
141
        );
142
143
        $mockedService->create($sourceUrl, $destinationUrl, $forward);
144
    }
145
146
    public function providerForTestCreate()
147
    {
148
        return array(
149
            array('fruit', 'food', true),
150
            array(' /fruit/ ', ' /food/ ', true),
151
            array('/fruit/*', '/food', false),
152
            array('/fruit/*', '/food/{1}', true),
153
            array('/fruit/*/*', '/food/{1}', true),
154
            array('/fruit/*/*', '/food/{2}', true),
155
            array('/fruit/*/*', '/food/{1}/{2}', true),
156
        );
157
    }
158
159
    /**
160
     * Test for the create() method.
161
     *
162
     * @depends testConstructor
163
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::create
164
     * @dataProvider providerForTestCreate
165
     */
166
    public function testCreate($sourceUrl, $destinationUrl, $forward)
167
    {
168
        $mockedService = $this->getPartlyMockedURLWildcardService();
169
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
170
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
171
        $repositoryMock = $this->getRepositoryMock();
172
173
        $sourceUrl = '/' . trim($sourceUrl, '/ ');
174
        $destinationUrl = '/' . trim($destinationUrl, '/ ');
175
176
        $repositoryMock->expects(
177
            $this->once()
178
        )->method(
179
            'hasAccess'
180
        )->with(
181
            $this->equalTo('content'),
182
            $this->equalTo('urltranslator')
183
        )->will(
184
            $this->returnValue(true)
185
        );
186
187
        $repositoryMock->expects($this->once())->method('beginTransaction');
188
        $repositoryMock->expects($this->once())->method('commit');
189
190
        $handlerMock->expects(
191
            $this->once()
192
        )->method(
193
            'loadAll'
194
        )->will(
195
            $this->returnValue(array())
196
        );
197
198
        $handlerMock->expects(
199
            $this->once()
200
        )->method(
201
            'create'
202
        )->with(
203
            $this->equalTo($sourceUrl),
204
            $this->equalTo($destinationUrl),
205
            $this->equalTo($forward)
206
        )->will(
207
            $this->returnValue(
208
                new SPIURLWildcard(
209
                    array(
210
                        'id' => 123456,
211
                        'sourceUrl' => $sourceUrl,
212
                        'destinationUrl' => $destinationUrl,
213
                        'forward' => $forward,
214
                    )
215
                )
216
            )
217
        );
218
219
        $urlWildCard = $mockedService->create($sourceUrl, $destinationUrl, $forward);
220
221
        $this->assertEquals(
222
            new URLWildcard(
223
                array(
224
                    'id' => 123456,
225
                    'sourceUrl' => $sourceUrl,
226
                    'destinationUrl' => $destinationUrl,
227
                    'forward' => $forward,
228
                )
229
            ),
230
            $urlWildCard
231
        );
232
    }
233
234
    /**
235
     * Test for the create() method.
236
     *
237
     * @depends testConstructor
238
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::create
239
     * @expectedException \Exception
240
     */
241
    public function testCreateWithRollback()
242
    {
243
        $mockedService = $this->getPartlyMockedURLWildcardService();
244
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
245
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
246
        $repositoryMock = $this->getRepositoryMock();
247
248
        $repositoryMock->expects(
249
            $this->once()
250
        )->method(
251
            'hasAccess'
252
        )->with(
253
            $this->equalTo('content'),
254
            $this->equalTo('urltranslator')
255
        )->will(
256
            $this->returnValue(true)
257
        );
258
259
        $repositoryMock->expects($this->once())->method('beginTransaction');
260
        $repositoryMock->expects($this->once())->method('rollback');
261
262
        $handlerMock->expects(
263
            $this->once()
264
        )->method(
265
            'loadAll'
266
        )->will(
267
            $this->returnValue(array())
268
        );
269
270
        $sourceUrl = '/lorem';
271
        $destinationUrl = '/ipsum';
272
        $forward = true;
273
274
        $handlerMock->expects(
275
            $this->once()
276
        )->method(
277
            'create'
278
        )->with(
279
            $this->equalTo($sourceUrl),
280
            $this->equalTo($destinationUrl),
281
            $this->equalTo($forward)
282
        )->will(
283
            $this->throwException(new \Exception())
284
        );
285
286
        $mockedService->create($sourceUrl, $destinationUrl, $forward);
287
    }
288
289
    /**
290
     * Test for the remove() method.
291
     *
292
     * @depends testConstructor
293
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::remove
294
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
295
     */
296
    public function testRemoveThrowsUnauthorizedException()
297
    {
298
        $wildcard = new URLWildcard(['id' => 'McBoom']);
299
300
        $mockedService = $this->getPartlyMockedURLWildcardService();
301
        $repositoryMock = $this->getRepositoryMock();
302
        $repositoryMock->expects(
303
            $this->once()
304
        )->method(
305
            'canUser'
306
        )->with(
307
            $this->equalTo('content'),
308
            $this->equalTo('urltranslator'),
309
            $this->equalTo($wildcard)
310
        )->will(
311
            $this->returnValue(false)
312
        );
313
314
        $repositoryMock->expects($this->never())->method('beginTransaction');
315
316
        $mockedService->remove($wildcard);
317
    }
318
319
    /**
320
     * Test for the remove() method.
321
     *
322
     * @depends testConstructor
323
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::remove
324
     */
325 View Code Duplication
    public function testRemove()
326
    {
327
        $wildcard = new URLWildcard(['id' => 'McBomb']);
328
329
        $mockedService = $this->getPartlyMockedURLWildcardService();
330
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
331
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
332
        $repositoryMock = $this->getRepositoryMock();
333
334
        $repositoryMock->expects(
335
            $this->once()
336
        )->method(
337
            'canUser'
338
        )->with(
339
            $this->equalTo('content'),
340
            $this->equalTo('urltranslator'),
341
            $this->equalTo($wildcard)
342
        )->will(
343
            $this->returnValue(true)
344
        );
345
346
        $repositoryMock->expects($this->once())->method('beginTransaction');
347
        $repositoryMock->expects($this->once())->method('commit');
348
349
        $handlerMock->expects(
350
            $this->once()
351
        )->method(
352
            'remove'
353
        )->with(
354
            $this->equalTo('McBomb')
355
        );
356
357
        $mockedService->remove($wildcard);
358
    }
359
360
    /**
361
     * Test for the remove() method.
362
     *
363
     * @depends testConstructor
364
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::remove
365
     * @expectedException \Exception
366
     */
367 View Code Duplication
    public function testRemoveWithRollback()
368
    {
369
        $wildcard = new URLWildcard(['id' => 'McBoo']);
370
371
        $mockedService = $this->getPartlyMockedURLWildcardService();
372
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
373
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
374
        $repositoryMock = $this->getRepositoryMock();
375
376
        $repositoryMock->expects(
377
            $this->once()
378
        )->method(
379
            'canUser'
380
        )->with(
381
            $this->equalTo('content'),
382
            $this->equalTo('urltranslator'),
383
            $this->equalTo($wildcard)
384
        )->will(
385
            $this->returnValue(true)
386
        );
387
388
        $repositoryMock->expects($this->once())->method('beginTransaction');
389
        $repositoryMock->expects($this->once())->method('rollback');
390
391
        $handlerMock->expects(
392
            $this->once()
393
        )->method(
394
            'remove'
395
        )->with(
396
            $this->equalTo('McBoo')
397
        )->will(
398
            $this->throwException(new \Exception())
399
        );
400
401
        $mockedService->remove($wildcard);
402
    }
403
404
    /**
405
     * Test for the load() method.
406
     *
407
     * @depends testConstructor
408
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::remove
409
     * @expectedException \Exception
410
     */
411 View Code Duplication
    public function testLoadThrowsException()
412
    {
413
        $mockedService = $this->getPartlyMockedURLWildcardService();
414
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
415
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
416
417
        $handlerMock->expects(
418
            $this->once()
419
        )->method(
420
            'load'
421
        )->with(
422
            $this->equalTo('Luigi')
423
        )->will(
424
            $this->throwException(new \Exception())
425
        );
426
427
        $mockedService->load('Luigi');
428
    }
429
430
    /**
431
     * Test for the load() method.
432
     *
433
     * @depends testConstructor
434
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::remove
435
     */
436
    public function testLoad()
437
    {
438
        $mockedService = $this->getPartlyMockedURLWildcardService();
439
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
440
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
441
442
        $handlerMock->expects(
443
            $this->once()
444
        )->method(
445
            'load'
446
        )->with(
447
            $this->equalTo('Luigi')
448
        )->will(
449
            $this->returnValue(
450
                new SPIURLWildcard(
451
                    array(
452
                        'id' => 'Luigi',
453
                        'sourceUrl' => 'this',
454
                        'destinationUrl' => 'that',
455
                        'forward' => true,
456
                    )
457
                )
458
            )
459
        );
460
461
        $urlWildcard = $mockedService->load('Luigi');
462
463
        $this->assertEquals(
464
            new URLWildcard(
465
                array(
466
                    'id' => 'Luigi',
467
                    'sourceUrl' => 'this',
468
                    'destinationUrl' => 'that',
469
                    'forward' => true,
470
                )
471
            ),
472
            $urlWildcard
473
        );
474
    }
475
476
    /**
477
     * Test for the loadAll() method.
478
     *
479
     * @depends testConstructor
480
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::loadAll
481
     */
482 View Code Duplication
    public function testLoadAll()
483
    {
484
        $mockedService = $this->getPartlyMockedURLWildcardService();
485
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
486
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
487
488
        $handlerMock->expects(
489
            $this->once()
490
        )->method(
491
            'loadAll'
492
        )->with(
493
            $this->equalTo(0),
494
            $this->equalTo(-1)
495
        )->will(
496
            $this->returnValue(array())
497
        );
498
499
        $mockedService->loadAll();
500
    }
501
502
    /**
503
     * Test for the loadAll() method.
504
     *
505
     * @depends testConstructor
506
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::loadAll
507
     */
508
    public function testLoadAllWithLimitAndOffset()
509
    {
510
        $mockedService = $this->getPartlyMockedURLWildcardService();
511
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
512
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
513
514
        $handlerMock->expects(
515
            $this->once()
516
        )->method(
517
            'loadAll'
518
        )->with(
519
            $this->equalTo(12),
520
            $this->equalTo(34)
521
        )->will(
522
            $this->returnValue(
523
                array(
524
                    new SPIURLWildcard(
525
                        array(
526
                            'id' => 'Luigi',
527
                            'sourceUrl' => 'this',
528
                            'destinationUrl' => 'that',
529
                            'forward' => true,
530
                        )
531
                    ),
532
                )
533
            )
534
        );
535
536
        $urlWildcards = $mockedService->loadAll(12, 34);
537
538
        $this->assertEquals(
539
            array(
540
                new URLWildcard(
541
                    array(
542
                        'id' => 'Luigi',
543
                        'sourceUrl' => 'this',
544
                        'destinationUrl' => 'that',
545
                        'forward' => true,
546
                    )
547
                ),
548
            ),
549
            $urlWildcards
550
        );
551
    }
552
553
    /**
554
     * @return array
555
     */
556
    public function providerForTestTranslateThrowsNotFoundException()
557
    {
558
        return array(
559
            array(
560
                array(
561
                    'sourceUrl' => '/fruit',
562
                    'destinationUrl' => '/food',
563
                    'forward' => true,
564
                ),
565
                '/vegetable',
566
            ),
567
            array(
568
                array(
569
                    'sourceUrl' => '/fruit/apricot',
570
                    'destinationUrl' => '/food/apricot',
571
                    'forward' => true,
572
                ),
573
                '/fruit/lemon',
574
            ),
575
            array(
576
                array(
577
                    'sourceUrl' => '/fruit/*',
578
                    'destinationUrl' => '/food/{1}',
579
                    'forward' => true,
580
                ),
581
                '/fruit',
582
            ),
583
            array(
584
                array(
585
                    'sourceUrl' => '/fruit/*/*',
586
                    'destinationUrl' => '/food/{1}/{2}',
587
                    'forward' => true,
588
                ),
589
                '/fruit/citrus',
590
            ),
591
        );
592
    }
593
594
    /**
595
     * Test for the translate() method.
596
     *
597
     * @depends testConstructor
598
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::translate
599
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
600
     * @dataProvider providerForTestTranslateThrowsNotFoundException
601
     */
602 View Code Duplication
    public function testTranslateThrowsNotFoundException($createArray, $url)
603
    {
604
        $mockedService = $this->getPartlyMockedURLWildcardService();
605
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
606
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
607
608
        $handlerMock->expects(
609
            $this->once()
610
        )->method(
611
            'loadAll'
612
        )->with(
613
            $this->equalTo(0),
614
            $this->equalTo(-1)
615
        )->will(
616
            $this->returnValue(array(new SPIURLWildcard($createArray)))
617
        );
618
619
        $mockedService->translate($url);
620
    }
621
622
    /**
623
     * @return array
624
     */
625
    public function providerForTestTranslate()
626
    {
627
        return array(
628
            array(
629
                array(
630
                    'sourceUrl' => '/fruit/apricot',
631
                    'destinationUrl' => '/food/apricot',
632
                    'forward' => true,
633
                ),
634
                '/fruit/apricot',
635
                '/food/apricot',
636
            ),
637
            array(
638
                array(
639
                    'sourceUrl' => '/fruit/*',
640
                    'destinationUrl' => '/food/{1}',
641
                    'forward' => true,
642
                ),
643
                '/fruit/citrus',
644
                '/food/citrus',
645
            ),
646
            array(
647
                array(
648
                    'sourceUrl' => '/fruit/*',
649
                    'destinationUrl' => '/food/{1}',
650
                    'forward' => true,
651
                ),
652
                '/fruit/citrus/orange',
653
                '/food/citrus/orange',
654
            ),
655
            array(
656
                array(
657
                    'sourceUrl' => '/fruit/*/*',
658
                    'destinationUrl' => '/food/{2}',
659
                    'forward' => true,
660
                ),
661
                '/fruit/citrus/orange',
662
                '/food/orange',
663
            ),
664
            array(
665
                array(
666
                    'sourceUrl' => '/fruit/*/*',
667
                    'destinationUrl' => '/food/{1}/{2}',
668
                    'forward' => true,
669
                ),
670
                '/fruit/citrus/orange',
671
                '/food/citrus/orange',
672
            ),
673
            array(
674
                array(
675
                    'sourceUrl' => '/fruit/*/pamplemousse',
676
                    'destinationUrl' => '/food/weird',
677
                    'forward' => true,
678
                ),
679
                '/fruit/citrus/pamplemousse',
680
                '/food/weird',
681
            ),
682
            array(
683
                array(
684
                    'sourceUrl' => '/fruit/*/pamplemousse',
685
                    'destinationUrl' => '/food/weird/{1}',
686
                    'forward' => true,
687
                ),
688
                '/fruit/citrus/pamplemousse',
689
                '/food/weird/citrus',
690
            ),
691
            array(
692
                array(
693
                    'sourceUrl' => '/fruit/*/pamplemousse',
694
                    'destinationUrl' => '/food/weird/{1}',
695
                    'forward' => true,
696
                ),
697
                '/fruit/citrus/yellow/pamplemousse',
698
                '/food/weird/citrus/yellow',
699
            ),
700
        );
701
    }
702
703
    /**
704
     * Test for the translate() method.
705
     *
706
     * @depends testConstructor
707
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::translate
708
     * @dataProvider providerForTestTranslate
709
     */
710
    public function testTranslate($createArray, $url, $uri)
711
    {
712
        $mockedService = $this->getPartlyMockedURLWildcardService();
713
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
714
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
715
716
        $handlerMock->expects(
717
            $this->once()
718
        )->method(
719
            'loadAll'
720
        )->with(
721
            $this->equalTo(0),
722
            $this->equalTo(-1)
723
        )->will(
724
            $this->returnValue(array(new SPIURLWildcard($createArray)))
725
        );
726
727
        $translationResult = $mockedService->translate($url);
728
729
        $this->assertEquals(
730
            new URLWildcardTranslationResult(
731
                array(
732
                    'uri' => $uri,
733
                    'forward' => $createArray['forward'],
734
                )
735
            ),
736
            $translationResult
737
        );
738
    }
739
740
    /**
741
     * Test for the translate() method.
742
     *
743
     * @depends testConstructor
744
     * @covers \eZ\Publish\Core\Repository\URLWildcardService::translate
745
     */
746
    public function testTranslateUsesLongestMatchingWildcard()
747
    {
748
        $mockedService = $this->getPartlyMockedURLWildcardService();
749
        /** @var \PHPUnit_Framework_MockObject_MockObject $handlerMock */
750
        $handlerMock = $this->getPersistenceMock()->urlWildcardHandler();
751
752
        $handlerMock->expects(
753
            $this->once()
754
        )->method(
755
            'loadAll'
756
        )->with(
757
            $this->equalTo(0),
758
            $this->equalTo(-1)
759
        )->will(
760
            $this->returnValue(
761
                array(
762
                    new SPIURLWildcard(
763
                        array(
764
                            'sourceUrl' => '/something/*',
765
                            'destinationUrl' => '/short',
766
                            'forward' => true,
767
                        )
768
                    ),
769
                    new SPIURLWildcard(
770
                        array(
771
                            'sourceUrl' => '/something/something/*',
772
                            'destinationUrl' => '/long',
773
                            'forward' => false,
774
                        )
775
                    ),
776
                )
777
            )
778
        );
779
780
        $translationResult = $mockedService->translate('/something/something/thing');
781
782
        $this->assertEquals(
783
            new URLWildcardTranslationResult(
784
                array(
785
                    'uri' => '/long',
786
                    'forward' => false,
787
                )
788
            ),
789
            $translationResult
790
        );
791
    }
792
793
    /**
794
     * Returns the content service to test with $methods mocked.
795
     *
796
     * Injected Repository comes from {@see getRepositoryMock()} and persistence handler from {@see getPersistenceMock()}
797
     *
798
     * @param string[] $methods
799
     *
800
     * @return \eZ\Publish\Core\Repository\URLWildcardService|\PHPUnit_Framework_MockObject_MockObject
801
     */
802
    protected function getPartlyMockedURLWildcardService(array $methods = null)
803
    {
804
        return $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
805
            'eZ\\Publish\\Core\\Repository\\URLWildcardService',
806
            $methods,
0 ignored issues
show
Bug introduced by
It seems like $methods defined by parameter $methods on line 802 can also be of type null; however, eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
807
            array(
808
                $this->getRepositoryMock(),
809
                $this->getPersistenceMock()->urlWildcardHandler(),
810
            )
811
        );
812
    }
813
}
814