Skip to content

Commit ab1536a

Browse files
committed
Merge branch '8.x' into 9.x
# Conflicts: # CHANGELOG-8.x.md # src/Illuminate/Foundation/Application.php # src/Illuminate/Routing/Route.php # tests/Routing/RoutingRouteTest.php
2 parents 2794f81 + 0012549 commit ab1536a

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/Illuminate/Routing/Route.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ protected function parseControllerCallback()
314314
*/
315315
public function flushController()
316316
{
317+
$this->computedMiddleware = null;
317318
$this->controller = null;
318319
}
319320

tests/Routing/RoutingRouteTest.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,28 @@ public function testResponseIsReturned()
19391939
$this->assertNotInstanceOf(JsonResponse::class, $response);
19401940
}
19411941

1942+
public function testRouteFlushController()
1943+
{
1944+
$container = new Container;
1945+
$router = $this->getRouter();
1946+
1947+
$router->get('count', ActionCountStub::class);
1948+
$request = Request::create('count', 'GET');
1949+
1950+
$response = $router->dispatch($request);
1951+
$this->assertSame(1, $response->original['invokedCount']);
1952+
$this->assertSame(1, $response->original['middlewareInvokedCount']);
1953+
1954+
$response = $router->dispatch($request);
1955+
$this->assertSame(2, $response->original['invokedCount']);
1956+
$this->assertSame(2, $response->original['middlewareInvokedCount']);
1957+
1958+
$request->route()->flushController();
1959+
$response = $router->dispatch($request);
1960+
$this->assertSame(1, $response->original['invokedCount']);
1961+
$this->assertSame(1, $response->original['middlewareInvokedCount']);
1962+
}
1963+
19421964
public function testJsonResponseIsReturned()
19431965
{
19441966
$router = $this->getRouter();
@@ -2522,15 +2544,29 @@ public function __invoke()
25222544
}
25232545
}
25242546

2525-
class ActionCountStub
2547+
class ActionCountStub extends Controller
25262548
{
2527-
protected $count = 0;
2549+
protected $middlewareInvokedCount = 0;
2550+
2551+
protected $invokedCount = 0;
2552+
2553+
public function __construct()
2554+
{
2555+
$this->middleware(function ($request, $next) {
2556+
$this->middlewareInvokedCount++;
2557+
2558+
return $next($request);
2559+
});
2560+
}
25282561

25292562
public function __invoke()
25302563
{
2531-
$this->count++;
2564+
$this->invokedCount++;
25322565

2533-
return $this->count;
2566+
return [
2567+
'invokedCount' => $this->invokedCount,
2568+
'middlewareInvokedCount' => $this->middlewareInvokedCount,
2569+
];
25342570
}
25352571
}
25362572

0 commit comments

Comments
 (0)