Skip to content

Commit 9ad7852

Browse files
Fixes tests for middleware registration.
1 parent f9eba53 commit 9ad7852

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

tests/ServiceProviderTest.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Laragear\Preload\Http\Middleware\PreloadMiddleware;
1111
use Laragear\Preload\Preloader;
1212
use Laragear\Preload\PreloadServiceProvider;
13+
use function get_class;
14+
use function method_exists;
1315

1416
class ServiceProviderTest extends TestCase
1517
{
@@ -51,9 +53,13 @@ protected function usesProductionEnvironment(Application $app): void
5153
*/
5254
public function test_registers_global_middleware_on_production(): void
5355
{
54-
static::assertTrue(
55-
$this->app->make(Kernel::class)->hasMiddleware(PreloadMiddleware::class)
56-
);
56+
$http = $this->app->make(Kernel::class);
57+
58+
if (!method_exists($http, 'pushMiddleware')) {
59+
$this->markTestSkipped('The ' . get_class($http) . ' does not have a pushMiddleware() method to test.');
60+
}
61+
62+
static::assertTrue($http->hasMiddleware(PreloadMiddleware::class));
5763
}
5864

5965
protected function setConfigEnableTrue(Application $app): void
@@ -66,9 +72,13 @@ protected function setConfigEnableTrue(Application $app): void
6672
*/
6773
public function test_registers_global_middleware_when_config_is_true(): void
6874
{
69-
static::assertTrue(
70-
app(Kernel::class)->hasMiddleware(PreloadMiddleware::class)
71-
);
75+
$http = $this->app->make(Kernel::class);
76+
77+
if (!method_exists($http, 'pushMiddleware')) {
78+
$this->markTestSkipped('The ' . get_class($http) . ' does not have a pushMiddleware() method to test.');
79+
}
80+
81+
static::assertTrue($http->hasMiddleware(PreloadMiddleware::class));
7282
}
7383

7484
public function test_registers_command(): void

0 commit comments

Comments
 (0)