|
27 | 27 | use PHPUnit\Framework\Attributes\DataProvider; |
28 | 28 | use PHPUnit\Framework\Attributes\Group; |
29 | 29 | use Tests\Support\Controllers\Hello; |
| 30 | +use Tests\Support\Router\RouteCollectionSubclass; |
30 | 31 |
|
31 | 32 | /** |
32 | 33 | * @internal |
@@ -314,6 +315,38 @@ static function ($routes): void { |
314 | 315 | $this->assertSame($expected, $routes->getRoutes()); |
315 | 316 | } |
316 | 317 |
|
| 318 | + public function testGroupingPassesSubclassToNestedCallbacks(): void |
| 319 | + { |
| 320 | + $modules = new Modules(); |
| 321 | + $modules->enabled = false; |
| 322 | + $config = new Routing(); |
| 323 | + $config->defaultNamespace = '\\'; |
| 324 | + $routes = new RouteCollectionSubclass(service('locator'), $modules, $config); |
| 325 | + $routes->setHTTPVerb(Method::GET); |
| 326 | + |
| 327 | + $routes->group('admin', ['namespace' => 'Admin', 'filter' => ['csrf']], function (RouteCollectionSubclass $group) use ($routes): void { |
| 328 | + $this->assertSame($routes, $group); |
| 329 | + |
| 330 | + $group->group('profile', ['filter' => ['honeypot']], function (RouteCollectionSubclass $nested) use ($routes): void { |
| 331 | + $this->assertSame($routes, $nested); |
| 332 | + $nested->get('show', 'Profile::show'); |
| 333 | + }); |
| 334 | + |
| 335 | + $group->get('dashboard', 'Dashboard::index'); |
| 336 | + }); |
| 337 | + |
| 338 | + $routes->get('home', 'Home::index'); |
| 339 | + |
| 340 | + $this->assertSame([ |
| 341 | + 'admin/profile/show' => '\\Admin\\Profile::show', |
| 342 | + 'admin/dashboard' => '\\Admin\\Dashboard::index', |
| 343 | + 'home' => '\\Home::index', |
| 344 | + ], $routes->getRoutes(Method::GET)); |
| 345 | + $this->assertSame(['csrf', 'honeypot'], $routes->getFiltersForRoute('admin/profile/show')); |
| 346 | + $this->assertSame(['csrf'], $routes->getFiltersForRoute('admin/dashboard')); |
| 347 | + $this->assertFalse($routes->isFiltered('home')); |
| 348 | + } |
| 349 | + |
317 | 350 | public function testGroupGetsSanitized(): void |
318 | 351 | { |
319 | 352 | $routes = $this->getCollector(); |
|
0 commit comments