|
15 | 15 | use Symfony\Component\Config\FileLocator;
|
16 | 16 | use Symfony\Component\Config\Loader\DelegatingLoader;
|
17 | 17 | use Symfony\Component\Config\Loader\LoaderResolver;
|
| 18 | +use Symfony\Component\Routing\Exception\InvalidArgumentException; |
18 | 19 | use Symfony\Component\Routing\Loader\AttributeClassLoader;
|
19 | 20 | use Symfony\Component\Routing\Loader\Psr4DirectoryLoader;
|
20 | 21 | use Symfony\Component\Routing\Route;
|
@@ -90,6 +91,34 @@ public static function provideNamespacesThatNeedTrimming(): array
|
90 | 91 | ];
|
91 | 92 | }
|
92 | 93 |
|
| 94 | + /** |
| 95 | + * @dataProvider provideInvalidPsr4Namespaces |
| 96 | + */ |
| 97 | + public function testInvalidPsr4Namespace(string $namespace, string $expectedExceptionMessage) |
| 98 | + { |
| 99 | + $this->expectException(InvalidArgumentException::class); |
| 100 | + $this->expectExceptionMessage($expectedExceptionMessage); |
| 101 | + |
| 102 | + $this->getLoader()->load( |
| 103 | + ['path' => 'Psr4Controllers', 'namespace' => $namespace], |
| 104 | + 'attribute' |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public static function provideInvalidPsr4Namespaces(): array |
| 109 | + { |
| 110 | + return [ |
| 111 | + 'slash instead of back-slash' => [ |
| 112 | + 'namespace' => 'App\Application/Controllers', |
| 113 | + 'exceptionMessage' => 'Namespace "App\Application/Controllers" is not a valid PSR-4 prefix.', |
| 114 | + ], |
| 115 | + 'invalid namespace' => [ |
| 116 | + 'namespace' => 'App\Contro llers', |
| 117 | + 'exceptionMessage' => 'Namespace "App\Contro llers" is not a valid PSR-4 prefix.', |
| 118 | + ], |
| 119 | + ]; |
| 120 | + } |
| 121 | + |
93 | 122 | private function loadPsr4Controllers(): RouteCollection
|
94 | 123 | {
|
95 | 124 | return $this->getLoader()->load(
|
|
0 commit comments