Skip to content

Commit

Permalink
Allow "missing" method to be used on route groups (#49144)
Browse files Browse the repository at this point in the history
* Allow missing method to be used on route groups

* Code style
  • Loading branch information
redelschaap authored Nov 27, 2023
1 parent cc374af commit e846535
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @method \Illuminate\Routing\RouteRegistrar controller(string $controller)
* @method \Illuminate\Routing\RouteRegistrar domain(string $value)
* @method \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
* @method \Illuminate\Routing\RouteRegistrar missing(\Closure $missing)
* @method \Illuminate\Routing\RouteRegistrar name(string $value)
* @method \Illuminate\Routing\RouteRegistrar namespace(string|null $value)
* @method \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
Expand Down Expand Up @@ -65,6 +66,7 @@ class RouteRegistrar
'controller',
'domain',
'middleware',
'missing',
'name',
'namespace',
'prefix',
Expand Down
4 changes: 2 additions & 2 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ public function testRouteGroupChaining()
public function testRegisteringNonApprovedAttributesThrows()
{
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Method Illuminate\Routing\RouteRegistrar::missing does not exist.');
$this->expectExceptionMessage('Method Illuminate\Routing\RouteRegistrar::unsupportedMethod does not exist.');

$this->router->domain('foo')->missing('bar')->group(function ($router) {
$this->router->domain('foo')->unsupportedMethod('bar')->group(function ($router) {
//
});
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,29 @@ public function testImplicitBindingsWithMissingModelHandledByMissing()
$this->assertEquals(302, $response->getStatusCode());
}

public function testImplicitBindingsWithMissingModelHandledByMissingOnGroupLevel()
{
$router = $this->getRouter();
$router->as('foo.')
->missing(fn () => new RedirectResponse('/', 302))
->group(function () use ($router) {
$router->get('foo/{bar}', [
'middleware' => SubstituteBindings::class,
'uses' => function (RouteModelBindingNullStub $bar = null) {
$this->assertInstanceOf(RouteModelBindingNullStub::class, $bar);

return $bar->first();
},
]);
});

$request = Request::create('foo/taylor', 'GET');

$response = $router->dispatch($request);
$this->assertTrue($response->isRedirect('/'));
$this->assertEquals(302, $response->getStatusCode());
}

public function testImplicitBindingsWithOptionalParameterWithNoKeyInUri()
{
$router = $this->getRouter();
Expand Down

0 comments on commit e846535

Please sign in to comment.