@@ -1939,6 +1939,28 @@ public function testResponseIsReturned()
1939
1939
$ this ->assertNotInstanceOf (JsonResponse::class, $ response );
1940
1940
}
1941
1941
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
+
1942
1964
public function testJsonResponseIsReturned ()
1943
1965
{
1944
1966
$ router = $ this ->getRouter ();
@@ -2522,15 +2544,29 @@ public function __invoke()
2522
2544
}
2523
2545
}
2524
2546
2525
- class ActionCountStub
2547
+ class ActionCountStub extends Controller
2526
2548
{
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
+ }
2528
2561
2529
2562
public function __invoke ()
2530
2563
{
2531
- $ this ->count ++;
2564
+ $ this ->invokedCount ++;
2532
2565
2533
- return $ this ->count ;
2566
+ return [
2567
+ 'invokedCount ' => $ this ->invokedCount ,
2568
+ 'middlewareInvokedCount ' => $ this ->middlewareInvokedCount ,
2569
+ ];
2534
2570
}
2535
2571
}
2536
2572
0 commit comments