ManagerTest::testGetCliBootstrappers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Module;
6
7
use AbterPhp\Framework\Constant\Event;
8
use AbterPhp\Framework\Constant\Module;
9
use Opulence\Cache\ICacheBridge;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
13
class ManagerTest extends TestCase
14
{
15
    /** @var Manager - System Under Test */
16
    protected Manager $sut;
17
18
    /** @var Loader|MockObject */
19
    protected $loaderMock;
20
21
    /** @var ICacheBridge|null|MockObject */
22
    protected $cacheMock;
23
24
    public function setUp(): void
25
    {
26
        $this->cacheMock = null;
27
28
        $this->loaderMock = $this->createMock(Loader::class);
29
30
        $this->sut = new Manager($this->loaderMock);
31
32
        parent::setUp();
33
    }
34
35
    public function createSutWithCache(): void
36
    {
37
        $this->cacheMock = $this->createMock(Loader::class);
38
39
        $this->sut = new Manager($this->loaderMock, $this->cacheMock);
40
41
        parent::setUp();
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function getHttpBootstrapperProvider(): array
48
    {
49
        return [
50
            'no-modules'  => [[], []],
51
            'one-module'  => [
52
                [
53
                    [
54
                        Module::BOOTSTRAPPERS      => [
55
                            'Assets\Bootstrappers\AssetManagerBootstrapper',
56
                            'Template\Bootstrappers\TemplateEngineBootstrapper',
57
                        ],
58
                        Module::CLI_BOOTSTRAPPERS  => [
59
                            'Databases\Bootstrappers\MigrationsBootstrapper',
60
                        ],
61
                        Module::HTTP_BOOTSTRAPPERS => [
62
                            'Navigation\Bootstrappers\PrimaryBootstrapper',
63
                            'Views\Bootstrappers\ViewFunctionsBootstrapper',
64
                        ],
65
                    ],
66
                ],
67
                [
68
                    'Assets\Bootstrappers\AssetManagerBootstrapper',
69
                    'Template\Bootstrappers\TemplateEngineBootstrapper',
70
                    'Navigation\Bootstrappers\PrimaryBootstrapper',
71
                    'Views\Bootstrappers\ViewFunctionsBootstrapper',
72
                ],
73
            ],
74
            'two-modules' => [
75
                [
76
                    [
77
                        Module::BOOTSTRAPPERS      => [
78
                            'Assets\Bootstrappers\AssetManagerBootstrapper',
79
                            'Template\Bootstrappers\TemplateEngineBootstrapper',
80
                        ],
81
                        Module::CLI_BOOTSTRAPPERS  => [
82
                            'Databases\Bootstrappers\MigrationsBootstrapper',
83
                        ],
84
                        Module::HTTP_BOOTSTRAPPERS => [
85
                            'Navigation\Bootstrappers\PrimaryBootstrapper',
86
                            'Views\Bootstrappers\ViewFunctionsBootstrapper',
87
                        ],
88
                    ],
89
                    [
90
                        Module::BOOTSTRAPPERS      => [
91
                            'Bootstrappers\Orm\OrmBootstrapper',
92
                            'Bootstrappers\Validation\ValidatorBootstrapper',
93
                        ],
94
                        Module::CLI_BOOTSTRAPPERS  => [
95
                            'Bootstrappers\Console\Commands\CommandsBootstrapper',
96
                        ],
97
                        Module::HTTP_BOOTSTRAPPERS => [
98
                            'Bootstrappers\Http\Controllers\Execute\LoginBootstrapper',
99
                            'Bootstrappers\Vendor\SlugifyBootstrapper',
100
                        ],
101
                    ],
102
                    [],
103
                ],
104
                [
105
                    'Assets\Bootstrappers\AssetManagerBootstrapper',
106
                    'Template\Bootstrappers\TemplateEngineBootstrapper',
107
                    'Navigation\Bootstrappers\PrimaryBootstrapper',
108
                    'Views\Bootstrappers\ViewFunctionsBootstrapper',
109
                    'Bootstrappers\Orm\OrmBootstrapper',
110
                    'Bootstrappers\Validation\ValidatorBootstrapper',
111
                    'Bootstrappers\Http\Controllers\Execute\LoginBootstrapper',
112
                    'Bootstrappers\Vendor\SlugifyBootstrapper',
113
                ],
114
            ],
115
116
        ];
117
    }
118
119
    /**
120
     * @dataProvider getHttpBootstrapperProvider
121
     *
122
     * @param array $modules
123
     * @param array $expectedResult
124
     */
125
    public function testGetHttpBootstrappers(array $modules, array $expectedResult): void
126
    {
127
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
128
129
        $actualResult = $this->sut->getHttpBootstrappers();
130
131
        $this->assertEquals($expectedResult, $actualResult);
132
    }
133
134
    /**
135
     * @return array
136
     */
137
    public function getCliBootstrapperProvider(): array
138
    {
139
        return [
140
            'no-modules'  => [[], []],
141
            'one-module'  => [
142
                [
143
                    [
144
                        Module::BOOTSTRAPPERS      => [
145
                            'Assets\Bootstrappers\AssetManagerBootstrapper',
146
                            'Template\Bootstrappers\TemplateEngineBootstrapper',
147
                        ],
148
                        Module::CLI_BOOTSTRAPPERS  => [
149
                            'Databases\Bootstrappers\MigrationsBootstrapper',
150
                        ],
151
                        Module::HTTP_BOOTSTRAPPERS => [
152
                            'Navigation\Bootstrappers\PrimaryBootstrapper',
153
                            'Views\Bootstrappers\ViewFunctionsBootstrapper',
154
                        ],
155
                    ],
156
                ],
157
                [
158
                    'Assets\Bootstrappers\AssetManagerBootstrapper',
159
                    'Template\Bootstrappers\TemplateEngineBootstrapper',
160
                    'Databases\Bootstrappers\MigrationsBootstrapper',
161
                ],
162
            ],
163
            'two-modules' => [
164
                [
165
                    [
166
                        Module::BOOTSTRAPPERS      => [
167
                            'Assets\Bootstrappers\AssetManagerBootstrapper',
168
                            'Template\Bootstrappers\TemplateEngineBootstrapper',
169
                        ],
170
                        Module::CLI_BOOTSTRAPPERS  => [
171
                            'Databases\Bootstrappers\MigrationsBootstrapper',
172
                        ],
173
                        Module::HTTP_BOOTSTRAPPERS => [
174
                            'Navigation\Bootstrappers\PrimaryBootstrapper',
175
                            'Views\Bootstrappers\ViewFunctionsBootstrapper',
176
                        ],
177
                    ],
178
                    [
179
                        Module::BOOTSTRAPPERS      => [
180
                            'Bootstrappers\Orm\OrmBootstrapper',
181
                            'Bootstrappers\Validation\ValidatorBootstrapper',
182
                        ],
183
                        Module::CLI_BOOTSTRAPPERS  => [
184
                            'Bootstrappers\Console\Commands\CommandsBootstrapper',
185
                        ],
186
                        Module::HTTP_BOOTSTRAPPERS => [
187
                            'Bootstrappers\Http\Controllers\Execute\LoginBootstrapper',
188
                            'Bootstrappers\Vendor\SlugifyBootstrapper',
189
                        ],
190
                    ],
191
                    [],
192
                ],
193
                [
194
                    'Assets\Bootstrappers\AssetManagerBootstrapper',
195
                    'Template\Bootstrappers\TemplateEngineBootstrapper',
196
                    'Databases\Bootstrappers\MigrationsBootstrapper',
197
                    'Bootstrappers\Orm\OrmBootstrapper',
198
                    'Bootstrappers\Validation\ValidatorBootstrapper',
199
                    'Bootstrappers\Console\Commands\CommandsBootstrapper',
200
                ],
201
            ],
202
203
        ];
204
    }
205
206
    /**
207
     * @dataProvider getCliBootstrapperProvider
208
     *
209
     * @param array $modules
210
     * @param array $expectedResult
211
     */
212
    public function testGetCliBootstrappers(array $modules, array $expectedResult): void
213
    {
214
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
215
216
        $actualResult = $this->sut->getCliBootstrappers();
217
218
        $this->assertEquals($expectedResult, $actualResult);
219
    }
220
221
    /**
222
     * @return array
223
     */
224
    public function getCommandsProvider(): array
225
    {
226
        return [
227
            'no-modules'  => [[], []],
228
            'one-module'  => [
229
                [
230
                    [
231
                        Module::COMMANDS => [
232
                            'Console\Commands\User\Create',
233
                            'Console\Commands\User\Delete',
234
                        ],
235
                    ],
236
                ],
237
                [
238
                    'Console\Commands\User\Create',
239
                    'Console\Commands\User\Delete',
240
                ],
241
            ],
242
            'two-modules' => [
243
                [
244
                    [
245
                        Module::COMMANDS => [
246
                            'Console\Commands\User\Create',
247
                            'Console\Commands\User\Delete',
248
                        ],
249
                    ],
250
                    [
251
                        Module::COMMANDS => [
252
                            'Assets\Command\FlushCache',
253
                            'Authorization\Command\FlushCache',
254
                        ],
255
                    ],
256
                    [],
257
                ],
258
                [
259
                    'Console\Commands\User\Create',
260
                    'Console\Commands\User\Delete',
261
                    'Assets\Command\FlushCache',
262
                    'Authorization\Command\FlushCache',
263
                ],
264
            ],
265
266
        ];
267
    }
268
269
    /**
270
     * @dataProvider getCommandsProvider
271
     *
272
     * @param array $modules
273
     * @param array $expectedResult
274
     */
275
    public function testGetCommands(array $modules, array $expectedResult): void
276
    {
277
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
278
279
        $actualResult = $this->sut->getCommands();
280
281
        $this->assertEquals($expectedResult, $actualResult);
282
    }
283
284
    /**
285
     * @return array
286
     */
287
    public function getEventsProvider(): array
288
    {
289
        return [
290
            'no-modules'  => [[], []],
291
            'one-module'  => [
292
                [
293
                    [
294
                        Module::EVENTS => [
295
                            Event::TEMPLATE_ENGINE_READY => [
296
                                10 => ['Events\Listeners\TemplateRegistrar@register'],
297
                            ],
298
                            Event::NAVIGATION_READY      => [
299
                                10 => ['Events\Listeners\NavigationRegistrar@register'],
300
                            ],
301
                            Event::ENTITY_POST_CHANGE    => [
302
                                10 => ['Events\Listeners\PageInvalidator@register'],
303
                            ],
304
                            Event::DASHBOARD_READY       => [
305
                                10 => ['Events\Listeners\DashboardRegistrar@register'],
306
                            ],
307
                        ],
308
                    ],
309
                ],
310
                [
311
                    Event::TEMPLATE_ENGINE_READY => [
312
                        'Events\Listeners\TemplateRegistrar@register',
313
                    ],
314
                    Event::NAVIGATION_READY      => [
315
                        'Events\Listeners\NavigationRegistrar@register',
316
                    ],
317
                    Event::ENTITY_POST_CHANGE    => [
318
                        'Events\Listeners\PageInvalidator@register',
319
                    ],
320
                    Event::DASHBOARD_READY       => [
321
                        'Events\Listeners\DashboardRegistrar@register',
322
                    ],
323
                ],
324
            ],
325
            'two-modules' => [
326
                [
327
                    [
328
                        Module::EVENTS => [
329
                            Event::TEMPLATE_ENGINE_READY => [
330
                                10 => ['Module1\Events\Listeners\TemplateRegistrar@register'],
331
                            ],
332
                            Event::NAVIGATION_READY      => [
333
                                10 => ['Module1\Events\Listeners\NavigationRegistrar@register'],
334
                            ],
335
                            Event::ENTITY_POST_CHANGE    => [
336
                                10 => ['Module1\Events\Listeners\PageInvalidator@register'],
337
                            ],
338
                            Event::DASHBOARD_READY       => [
339
                                10 => ['Module1\Events\Listeners\DashboardRegistrar@register'],
340
                            ],
341
                        ],
342
                    ],
343
                    [
344
                        Module::EVENTS => [
345
                            Event::AUTH_READY          => [
346
                                10 => ['Module2\Events\Listeners\AuthRegistrar@register'],
347
                            ],
348
                            Event::NAVIGATION_READY    => [
349
                                10 => ['Module2\Events\Listeners\NavigationRegistrar@register'],
350
                            ],
351
                            Event::ENTITY_POST_CHANGE  => [
352
                                10 => ['Module2\Events\Listeners\AuthInvalidator@register'],
353
                            ],
354
                            Event::DASHBOARD_READY     => [
355
                                10 => ['Module2\Events\Listeners\DashboardRegistrar@register'],
356
                            ],
357
                            Event::FLUSH_COMMAND_READY => [],
358
                        ],
359
                    ],
360
                    [],
361
                ],
362
                [
363
                    Event::TEMPLATE_ENGINE_READY => [
364
                        'Module1\Events\Listeners\TemplateRegistrar@register',
365
                    ],
366
                    Event::NAVIGATION_READY      => [
367
                        'Module1\Events\Listeners\NavigationRegistrar@register',
368
                        'Module2\Events\Listeners\NavigationRegistrar@register',
369
                    ],
370
                    Event::ENTITY_POST_CHANGE    => [
371
                        'Module1\Events\Listeners\PageInvalidator@register',
372
                        'Module2\Events\Listeners\AuthInvalidator@register',
373
                    ],
374
                    Event::DASHBOARD_READY       => [
375
                        'Module1\Events\Listeners\DashboardRegistrar@register',
376
                        'Module2\Events\Listeners\DashboardRegistrar@register',
377
                    ],
378
                    Event::AUTH_READY            => [
379
                        'Module2\Events\Listeners\AuthRegistrar@register',
380
                    ],
381
                ],
382
            ],
383
384
        ];
385
    }
386
387
    /**
388
     * @dataProvider getEventsProvider
389
     *
390
     * @param array $modules
391
     * @param array $expectedResult
392
     */
393
    public function testGetEvents(array $modules, array $expectedResult): void
394
    {
395
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
396
397
        $actualResult = $this->sut->getEvents();
398
399
        $this->assertEquals($expectedResult, $actualResult);
400
    }
401
402
    /**
403
     * @return array
404
     */
405
    public function getMiddlewareProvider(): array
406
    {
407
        return [
408
            'no-modules'  => [[], []],
409
            'one-module'  => [
410
                [
411
                    [
412
                        Module::MIDDLEWARE => [
413
                            1000 => [
414
                                'Http\Middleware\CheckCsrfToken',
415
                                'Http\Middleware\Security',
416
                            ],
417
                        ],
418
                    ],
419
                ],
420
                [
421
                    'Http\Middleware\CheckCsrfToken',
422
                    'Http\Middleware\Security',
423
                ],
424
            ],
425
            'two-modules' => [
426
                [
427
                    [
428
                        Module::MIDDLEWARE => [
429
                            1000 => [
430
                                'Module1\Http\Middleware\CheckCsrfToken',
431
                                'Module1\Http\Middleware\Security',
432
                            ],
433
                        ],
434
                    ],
435
                    [
436
                        Module::MIDDLEWARE => [
437
                            500  => [
438
                                'Module2\Http\Middleware\Session',
439
                            ],
440
                            1000 => [
441
                                'Module2\Http\Middleware\EnvironmentWarning',
442
                                'Module2\Http\Middleware\Security',
443
                            ],
444
                        ],
445
                    ],
446
                    [],
447
                ],
448
                [
449
                    'Module2\Http\Middleware\Session',
450
                    'Module1\Http\Middleware\CheckCsrfToken',
451
                    'Module1\Http\Middleware\Security',
452
                    'Module2\Http\Middleware\EnvironmentWarning',
453
                    'Module2\Http\Middleware\Security',
454
                ],
455
            ],
456
        ];
457
    }
458
459
    /**
460
     * @dataProvider getMiddlewareProvider
461
     *
462
     * @param array $modules
463
     * @param array $expectedResult
464
     */
465
    public function testGetMiddleware(array $modules, array $expectedResult): void
466
    {
467
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
468
469
        $actualResult = $this->sut->getMiddleware();
470
471
        $this->assertEquals($expectedResult, $actualResult);
472
    }
473
474
    /**
475
     * @return array
476
     */
477
    public function getRoutePathsProvider(): array
478
    {
479
        return [
480
            'no-modules'  => [[], []],
481
            'one-module'  => [
482
                [
483
                    [
484
                        Module::ROUTE_PATHS => [
485
                            600   => [
486
                                'Module1/routes-early.php',
487
                                'Module1/routes-early2.php',
488
                            ],
489
                            50000 => [
490
                                'Module1/routes-late.php',
491
                            ],
492
                        ],
493
                    ],
494
                ],
495
                [
496
                    'Module1/routes-late.php',
497
                    'Module1/routes-early.php',
498
                    'Module1/routes-early2.php',
499
                ],
500
            ],
501
            'two-modules' => [
502
                [
503
                    [
504
                        Module::ROUTE_PATHS => [
505
                            600   => [
506
                                'Module1/routes-early.php',
507
                                'Module1/routes-early2.php',
508
                            ],
509
                            50000 => [
510
                                'Module1/routes-late.php',
511
                            ],
512
                        ],
513
                    ],
514
                    [
515
                        Module::ROUTE_PATHS => [
516
                            -20   => [
517
                                'Module2/routes-really-early.php',
518
                            ],
519
                            700   => [
520
                                'Module2/routes-early.php',
521
                            ],
522
                            50000 => [
523
                                'Module2/routes-late.php',
524
                            ],
525
                        ],
526
                    ],
527
                    [],
528
                ],
529
                [
530
                    'Module1/routes-late.php',
531
                    'Module2/routes-late.php',
532
                    'Module2/routes-early.php',
533
                    'Module1/routes-early.php',
534
                    'Module1/routes-early2.php',
535
                    'Module2/routes-really-early.php',
536
                ],
537
            ],
538
        ];
539
    }
540
541
    /**
542
     * @dataProvider getRoutePathsProvider
543
     *
544
     * @param array $modules
545
     * @param array $expectedResult
546
     */
547
    public function testGetRoutePaths(array $modules, array $expectedResult): void
548
    {
549
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
550
551
        $actualResult = $this->sut->getRoutePaths();
552
553
        $this->assertEquals($expectedResult, $actualResult);
554
    }
555
556
    /**
557
     * @return array
558
     */
559
    public function getMigrationPathsProvider(): array
560
    {
561
        return [
562
            'no-modules'  => [[], []],
563
            'one-module'  => [
564
                [
565
                    [
566
                        Module::MIGRATION_PATHS => [
567
                            600   => [
568
                                'Module1/migrations-early.php',
569
                                'Module1/migrations-early2.php',
570
                            ],
571
                            50000 => [
572
                                'Module1/migrations-late.php',
573
                            ],
574
                        ],
575
                    ],
576
                ],
577
                [
578
                    'Module1/migrations-early.php',
579
                    'Module1/migrations-early2.php',
580
                    'Module1/migrations-late.php',
581
                ],
582
            ],
583
            'two-modules' => [
584
                [
585
                    [
586
                        Module::MIGRATION_PATHS => [
587
                            600   => [
588
                                'Module1/migrations-early.php',
589
                                'Module1/migrations-early2.php',
590
                            ],
591
                            50000 => [
592
                                'Module1/migrations-late.php',
593
                            ],
594
                        ],
595
                    ],
596
                    [
597
                        Module::MIGRATION_PATHS => [
598
                            -20   => [
599
                                'Module2/migrations-really-early.php',
600
                            ],
601
                            700   => [
602
                                'Module2/migrations-early.php',
603
                            ],
604
                            50000 => [
605
                                'Module2/migrations-late.php',
606
                            ],
607
                        ],
608
                    ],
609
                    [],
610
                ],
611
                [
612
                    'Module2/migrations-really-early.php',
613
                    'Module1/migrations-early.php',
614
                    'Module1/migrations-early2.php',
615
                    'Module2/migrations-early.php',
616
                    'Module1/migrations-late.php',
617
                    'Module2/migrations-late.php',
618
                ],
619
            ],
620
        ];
621
    }
622
623
    /**
624
     * @dataProvider getMigrationPathsProvider
625
     *
626
     * @param array $modules
627
     * @param array $expectedResult
628
     */
629
    public function testGetMigrationPaths(array $modules, array $expectedResult): void
630
    {
631
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
632
633
        $actualResult = $this->sut->getMigrationPaths();
634
635
        $this->assertEquals($expectedResult, $actualResult);
636
    }
637
638
    /**
639
     * @return array
640
     */
641
    public function getResourcePathsProvider(): array
642
    {
643
        return [
644
            'no-modules'  => [[], []],
645
            'one-module'  => [
646
                [
647
                    [
648
                        Module::IDENTIFIER    => 'Module1',
649
                        Module::RESOURCE_PATH => 'Module1/resources',
650
                    ],
651
                ],
652
                [
653
                    'Module1' => 'Module1/resources',
654
                ],
655
            ],
656
            'two-modules' => [
657
                [
658
                    [
659
                        Module::IDENTIFIER    => 'Module1',
660
                        Module::RESOURCE_PATH => 'Module1/resources',
661
                    ],
662
                    [
663
                        Module::IDENTIFIER    => 'Module2',
664
                        Module::RESOURCE_PATH => 'Module2/resources',
665
                    ],
666
                    [],
667
                ],
668
                [
669
                    'Module1' => 'Module1/resources',
670
                    'Module2' => 'Module2/resources',
671
                ],
672
            ],
673
        ];
674
    }
675
676
    /**
677
     * @dataProvider getResourcePathsProvider
678
     *
679
     * @param array $modules
680
     * @param array $expectedResult
681
     */
682
    public function testGetResourcePath(array $modules, array $expectedResult): void
683
    {
684
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
685
686
        $actualResult = $this->sut->getResourcePaths();
687
688
        $this->assertEquals($expectedResult, $actualResult);
689
    }
690
691
    /**
692
     * @return array
693
     */
694
    public function getAssetsPathsProvider(): array
695
    {
696
        return [
697
            'no-modules'  => [[], []],
698
            'one-module'  => [
699
                [
700
                    [
701
                        Module::ASSETS_PATHS => [
702
                            'foo' => 'Module1/rawassets',
703
                            'bar' => 'Module1/rawassets',
704
                        ],
705
                    ],
706
                ],
707
                [
708
                    'foo' => [
709
                        'Module1/rawassets',
710
                    ],
711
                    'bar' => [
712
                        'Module1/rawassets',
713
                    ],
714
                ],
715
            ],
716
            'two-modules' => [
717
                [
718
                    [
719
                        Module::ASSETS_PATHS => [
720
                            'foo' => 'Module1/rawassets',
721
                            'bar' => 'Module1/rawassets',
722
                        ],
723
                    ],
724
                    [
725
                        Module::ASSETS_PATHS => [
726
                            'bar' => 'Module2/rawassets',
727
                            'baz' => 'Module2/rawassets',
728
                        ],
729
                    ],
730
                    [],
731
                ],
732
                [
733
                    'foo' => [
734
                        'Module1/rawassets',
735
                    ],
736
                    'bar' => [
737
                        'Module1/rawassets',
738
                        'Module2/rawassets',
739
                    ],
740
                    'baz' => [
741
                        'Module2/rawassets',
742
                    ],
743
                ],
744
            ],
745
        ];
746
    }
747
748
    /**
749
     * @dataProvider getAssetsPathsProvider
750
     *
751
     * @param array $modules
752
     * @param array $expectedResult
753
     */
754
    public function testGetAssetsPaths(array $modules, array $expectedResult): void
755
    {
756
        $this->loaderMock->expects($this->any())->method('loadModules')->willReturn($modules);
757
758
        $actualResult = $this->sut->getAssetsPaths();
759
760
        $this->assertEquals($expectedResult, $actualResult);
761
    }
762
763
    public function testInitCachesLoadedModules(): void
764
    {
765
        $modules = [];
766
767
        $this->loaderMock->expects($this->once())->method('loadModules')->willReturn($modules);
768
769
        $this->sut->getAssetsPaths();
770
        $this->sut->getAssetsPaths();
771
    }
772
773
    public function testCacheWrapperIgnoresCacheExceptionsOnChecking(): void
774
    {
775
        $this->cacheMock = $this->createCacheWrapper();
776
        $this->cacheMock
777
            ->expects($this->once())
778
            ->method('has')
779
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
780
            ->willThrowException(new \Exception());
781
782
        $this->sut = new Manager($this->loaderMock, $this->cacheMock);
783
784
        $modules = [];
785
786
        $this->loaderMock->expects($this->once())->method('loadModules')->willReturn($modules);
787
788
        $this->sut->getAssetsPaths();
789
    }
790
791
    public function testCacheWrapperIgnoresCacheExceptionsOnRead(): void
792
    {
793
        $this->cacheMock = $this->createCacheWrapper();
794
        $this->cacheMock
795
            ->expects($this->once())
796
            ->method('has')
797
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
798
            ->willReturn(true);
799
        $this->cacheMock
800
            ->expects($this->once())
801
            ->method('get')
802
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
803
            ->willThrowException(new \Exception());
804
805
        $this->sut = new Manager($this->loaderMock, $this->cacheMock);
806
807
        $modules = [];
808
809
        $this->loaderMock->expects($this->once())->method('loadModules')->willReturn($modules);
810
811
        $this->sut->getAssetsPaths();
812
    }
813
814
    public function testCacheWrapperIgnoresCacheExceptionsOnWrite(): void
815
    {
816
        $this->cacheMock = $this->createCacheWrapper();
817
        $this->cacheMock
818
            ->expects($this->once())
819
            ->method('has')
820
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
821
            ->willReturn(true);
822
        $this->cacheMock
823
            ->expects($this->once())
824
            ->method('get')
825
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
826
            ->willThrowException(new \Exception());
827
        $this->cacheMock
828
            ->expects($this->once())
829
            ->method('set')
830
            ->with(Manager::CACHE_KEY_ASSETS_PATHS)
831
            ->willThrowException(new \Exception());
832
833
        $this->sut = new Manager($this->loaderMock, $this->cacheMock);
834
835
        $modules = [];
836
837
        $this->loaderMock->expects($this->once())->method('loadModules')->willReturn($modules);
838
839
        $this->sut->getAssetsPaths();
840
    }
841
842
    /**
843
     * @return ICacheBridge|MockObject
844
     */
845
    protected function createCacheWrapper()
846
    {
847
        /** @var ICacheBridge|MockObject $cacheBridge */
848
        $cacheBridge = $this->createMock(ICacheBridge::class);
849
850
        return $cacheBridge;
851
    }
852
}
853