33namespace YlsIdeas \FeatureFlags \Tests ;
44
55use Illuminate \Contracts \Http \Kernel ;
6+ use Illuminate \Foundation \Configuration \Middleware ;
67use Illuminate \Support \Facades \Route ;
8+
9+ use function Orchestra \Testbench \after_resolving ;
10+
711use Orchestra \Testbench \TestCase ;
812use YlsIdeas \FeatureFlags \Facades \Features ;
913use YlsIdeas \FeatureFlags \FeatureFlagsServiceProvider ;
@@ -19,7 +23,7 @@ public function test_maintenance_mode_enabled()
1923 Route::get ('/ ' , fn () => 'Foo Bar ' );
2024
2125 $ this ->get ('/ ' )
22- ->assertStatus ( 503 );
26+ ->assertServiceUnavailable ( );
2327
2428 Features::assertAccessed ('system.down ' );
2529 }
@@ -70,9 +74,7 @@ public function test_upon_activation()
7074 $ this ->assertTrue ($ called );
7175 }
7276
73- /**
74- * @dataProvider exceptsValues
75- */
77+ #[\PHPUnit \Framework \Attributes \DataProvider('exceptsValues ' )]
7678 public function test_maintenance_mode_respects_excepts_values (string $ path , int $ status )
7779 {
7880 Features::fake (['system.down ' => true ]);
@@ -83,13 +85,15 @@ public function test_maintenance_mode_respects_excepts_values(string $path, int
8385 Route::get ('/ ' , fn () => 'Foo Bar ' );
8486 Route::get ('/test ' , fn () => 'Foo Bar Foo ' );
8587
86- $ this ->get ($ path )
88+ $ this
89+ ->withoutExceptionHandling ([\Symfony \Component \HttpKernel \Exception \HttpException::class])
90+ ->get ($ path )
8791 ->assertStatus ($ status );
8892
8993 Features::assertAccessed ('system.down ' );
9094 }
9195
92- public function exceptsValues (): \Generator
96+ public static function exceptsValues (): \Generator
9397 {
9498 yield 'blocked ' => [
9599 '/ ' , 503 ,
@@ -122,7 +126,7 @@ protected function defineEnvironment($app): void
122126 }
123127
124128 /**
125- * Resolve application HTTP Kernel implementation.
129+ * Required override for Pre Laravel 11
126130 *
127131 * @param \Illuminate\Foundation\Application $app
128132 * @return void
@@ -137,6 +141,26 @@ protected function resolveApplicationHttpKernel($app)
137141 );
138142 }
139143
144+ /**
145+ * Required override for Laravel 11
146+ *
147+ * @param \Illuminate\Foundation\Application $app
148+ * @return void
149+ */
150+ protected function resolveApplicationHttpMiddlewares ($ app )
151+ {
152+ after_resolving ($ app , Kernel::class, function ($ kernel , $ app ) {
153+ /** @var \Illuminate\Foundation\Http\Kernel $kernel */
154+ $ middleware = new Middleware ();
155+
156+ $ kernel ->setGlobalMiddleware ([
157+ \YlsIdeas \FeatureFlags \Middlewares \PreventRequestsDuringMaintenance::class,
158+ ]);
159+ $ kernel ->setMiddlewareGroups ($ middleware ->getMiddlewareGroups ());
160+ $ kernel ->setMiddlewareAliases ($ middleware ->getMiddlewareAliases ());
161+ });
162+ }
163+
140164 protected function getPackageProviders ($ app ): array
141165 {
142166 return [
0 commit comments