Skip to content

Commit 0012549

Browse files
authored
Fixes controller computed middleware (#44454)
1 parent 51abec6 commit 0012549

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/Illuminate/Routing/Route.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ protected function parseControllerCallback()
306306
*/
307307
public function flushController()
308308
{
309+
$this->computedMiddleware = null;
309310
$this->controller = null;
310311
}
311312

tests/Routing/RoutingRouteTest.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,14 +1772,17 @@ public function testRouteFlushController()
17721772
$request = Request::create('count', 'GET');
17731773

17741774
$response = $router->dispatch($request);
1775-
$this->assertSame(1, (int) $response->getContent());
1775+
$this->assertSame(1, $response->original['invokedCount']);
1776+
$this->assertSame(1, $response->original['middlewareInvokedCount']);
17761777

17771778
$response = $router->dispatch($request);
1778-
$this->assertSame(2, (int) $response->getContent());
1779+
$this->assertSame(2, $response->original['invokedCount']);
1780+
$this->assertSame(2, $response->original['middlewareInvokedCount']);
17791781

17801782
$request->route()->flushController();
17811783
$response = $router->dispatch($request);
1782-
$this->assertSame(1, (int) $response->getContent());
1784+
$this->assertSame(1, $response->original['invokedCount']);
1785+
$this->assertSame(1, $response->original['middlewareInvokedCount']);
17831786
}
17841787

17851788
public function testJsonResponseIsReturned()
@@ -2323,15 +2326,29 @@ public function __invoke()
23232326
}
23242327
}
23252328

2326-
class ActionCountStub
2329+
class ActionCountStub extends Controller
23272330
{
2328-
protected $count = 0;
2331+
protected $middlewareInvokedCount = 0;
2332+
2333+
protected $invokedCount = 0;
2334+
2335+
public function __construct()
2336+
{
2337+
$this->middleware(function ($request, $next) {
2338+
$this->middlewareInvokedCount++;
2339+
2340+
return $next($request);
2341+
});
2342+
}
23292343

23302344
public function __invoke()
23312345
{
2332-
$this->count++;
2346+
$this->invokedCount++;
23332347

2334-
return $this->count;
2348+
return [
2349+
'invokedCount' => $this->invokedCount,
2350+
'middlewareInvokedCount' => $this->middlewareInvokedCount,
2351+
];
23352352
}
23362353
}
23372354

0 commit comments

Comments
 (0)