| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (C) eZ Systems AS. All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license For full copyright and license information view LICENSE file distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace eZ\Publish\Core\MVC\Symfony\Templating\Tests\Twig\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use eZ\Publish\API\Repository\Values\Content\Content as APIContent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use eZ\Publish\API\Repository\Values\Content\ContentInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use eZ\Publish\API\Repository\Values\Content\Location as APILocation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGeneratorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\RoutingExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use eZ\Publish\Core\Repository\Values\Content\Content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use eZ\Publish\Core\Repository\Values\Content\Location; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use eZ\Publish\Core\Repository\Values\Content\VersionInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Symfony\Component\HttpFoundation\RequestStack; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Twig\Test\IntegrationTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | final class RoutingExtensionTest extends IntegrationTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected function getExtensions(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             new RoutingExtension( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 $this->getRouteReferenceGenerator(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 $this->getUrlGenerator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected function getFixturesDir(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return __DIR__ . '/_fixtures/routing_functions'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     protected function getExampleContent(int $id): APIContent | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         return new Content([ | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             'versionInfo' => new VersionInfo([ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                 'contentInfo' => $this->getExampleContentInfo($id), | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             ]), | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     protected function getExampleContentInfo(int $id): ContentInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return new ContentInfo([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             'id' => $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     protected function getExampleLocation(int $id): APILocation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return new Location(['id' => $id]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     protected function getExampleRouteReference($name, array $parameters = []): RouteReference | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return new RouteReference($name, $parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     private function getRouteReferenceGenerator(): RouteReferenceGeneratorInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $generator = new RouteReferenceGenerator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $this->createMock(EventDispatcherInterface::class) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $request = new Request(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $requestStack = new RequestStack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $requestStack->push($request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $generator->setRequestStack($requestStack); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         return $generator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     private function getUrlGenerator(): UrlGeneratorInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $generator = $this->createMock(UrlGeneratorInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $generator | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ->method('generate') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ->willReturnCallback(static function ($name, $parameters, $referenceType): string { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 return json_encode([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     '$name' => $name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                     '$parameters' => $parameters, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                     '$referenceType' => $referenceType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return $generator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  | 
            
                        
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.