diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 41f5b221d..060ad8fa1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.1, 8.2, 8.3, 8.4] + php: [8.1, 8.2, 8.3, 8.4, 8.5] laravel: [10, 11, 12] driver: [swoole, openswoole, 'roadrunner/frankenphp'] exclude: @@ -26,6 +26,10 @@ jobs: laravel: 12 - php: 8.4 laravel: 10 + - php: 8.5 + laravel: 10 + - php: 8.5 + laravel: 11 - php: 8.1 driver: openswoole diff --git a/composer.json b/composer.json index 8f8cdfb95..985a4d6df 100644 --- a/composer.json +++ b/composer.json @@ -29,9 +29,8 @@ "laravel/scout": "^10.2.1", "laravel/socialite": "^5.6.1", "livewire/livewire": "^2.12.3|^3.0", - "mockery/mockery": "^1.5.1", "nunomaduro/collision": "^6.4.0|^7.5.2|^8.0", - "orchestra/testbench": "^8.21|^9.0|^10.0", + "orchestra/testbench": "^8.36|^9.15|^10.8", "phpstan/phpstan": "^2.1.7", "phpunit/phpunit": "^10.4|^11.5", "spiral/roadrunner-cli": "^2.6.0", diff --git a/tests/BinaryBootstrapTest.php b/tests/BinaryBootstrapTest.php index 406ebd5ca..1aa383cba 100644 --- a/tests/BinaryBootstrapTest.php +++ b/tests/BinaryBootstrapTest.php @@ -2,30 +2,52 @@ namespace Laravel\Octane\Tests; +use Orchestra\Testbench\Foundation\Actions\DeleteVendorSymlink; +use Orchestra\Testbench\Foundation\Application as Testbench; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; +use function Orchestra\Testbench\default_skeleton_path; +use function Orchestra\Testbench\package_path; +use function Orchestra\Testbench\php_binary; + class BinaryBootstrapTest extends TestCase { + protected $app; + + protected function setUp(): void + { + parent::setUp(); + + $this->app = Testbench::createVendorSymlink(default_skeleton_path(), package_path('vendor')); + } + + protected function tearDown(): void + { + parent::tearDown(); + + (new DeleteVendorSymlink)->handle($this->app); + + unset($this->app); + } + public function test_it_can_retrieve_base_path_from_environment_variable() { - $basePath = realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel'); + $basePath = default_skeleton_path(); $process = Process::fromShellCommandline( - '"'.$this->phpBinary().'" base-path.php', __DIR__, ['APP_BASE_PATH' => $basePath], null, null + php_binary(escape: true).' base-path.php', __DIR__, ['APP_BASE_PATH' => $basePath], null, null ); $process->mustRun(); $output = $process->getOutput(); - if (\PHP_VERSION_ID >= 80100) { - $output = array_filter(explode("\n", $output), function ($output) { - return ! empty($output) && ! str_starts_with($output, 'Deprecated:'); - }); + $output = array_filter(explode("\n", $output), function ($output) { + return ! empty($output) && ! str_starts_with($output, 'Deprecated:'); + }); - $output = implode('', $output); - } + $output = implode('', $output); $this->assertSame($basePath, $output); } diff --git a/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php b/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php index 2b525a4fb..187980566 100644 --- a/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php +++ b/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php @@ -9,7 +9,7 @@ class EnsureRequestsDontExceedMaxExecutionTimeTest extends TestCase { - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_process_is_killed_if_current_request_exceeds_max_execution_time() { $table = new FakeTimerTable; diff --git a/tests/Listeners/CloseMonologHandlersTest.php b/tests/Listeners/CloseMonologHandlersTest.php index c03a85cdd..6d10e94ce 100644 --- a/tests/Listeners/CloseMonologHandlersTest.php +++ b/tests/Listeners/CloseMonologHandlersTest.php @@ -10,7 +10,6 @@ class CloseMonologHandlersTest extends TestCase { - /** @doesNotPerformAssertions */ public function test_logger_are_closed_after_worker_termination() { [$app, $worker, $client] = $this->createOctaneContext([ diff --git a/tests/Listeners/FlushMonologStateTest.php b/tests/Listeners/FlushMonologStateTest.php index f473918af..2b8bf78b1 100644 --- a/tests/Listeners/FlushMonologStateTest.php +++ b/tests/Listeners/FlushMonologStateTest.php @@ -10,7 +10,6 @@ class FlushMonologStateTest extends TestCase { - /** @doesNotPerformAssertions */ public function test_logger_are_reset() { [$app, $worker, $client] = $this->createOctaneContext([ diff --git a/tests/Listeners/FlushTranslatorCacheTest.php b/tests/Listeners/FlushTranslatorCacheTest.php index 9e12b15e4..379ea397d 100644 --- a/tests/Listeners/FlushTranslatorCacheTest.php +++ b/tests/Listeners/FlushTranslatorCacheTest.php @@ -8,7 +8,6 @@ class FlushTranslatorCacheTest extends TestCase { - /** @doesNotPerformAssertions */ public function test_parsed_keys_cache_is_flushed() { [$app, $worker, $client] = $this->createOctaneContext([ diff --git a/tests/Listeners/ReportExceptionTest.php b/tests/Listeners/ReportExceptionTest.php index ff7c6fa79..bb2755ef8 100644 --- a/tests/Listeners/ReportExceptionTest.php +++ b/tests/Listeners/ReportExceptionTest.php @@ -12,7 +12,7 @@ class ReportExceptionTest extends TestCase { - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_exceptions_are_streamed() { [$app, $worker] = $this->createOctaneContext([]); @@ -27,7 +27,7 @@ public function test_exceptions_are_streamed() $worker->dispatchEvent($app, new WorkerErrorOccurred($exception, $app)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_exceptions_are_reported() { [$app, $worker] = $this->createOctaneContext([]); @@ -49,7 +49,7 @@ public function test_exceptions_are_reported() $worker->dispatchEvent($app, new WorkerErrorOccurred($exception, $app)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_dd_calls_are_not_streamed() { [$app, $worker] = $this->createOctaneContext([]); diff --git a/tests/OnWorkerStartTest.php b/tests/OnWorkerStartTest.php index 2e355cfd8..ea727e5f2 100644 --- a/tests/OnWorkerStartTest.php +++ b/tests/OnWorkerStartTest.php @@ -7,6 +7,8 @@ use Laravel\Octane\Swoole\WorkerState; use Mockery; +use function Orchestra\Testbench\default_skeleton_path; + class OnWorkerStartTest extends TestCase { public function test_should_clear_opcache_returns_true_by_default(): void @@ -16,7 +18,6 @@ public function test_should_clear_opcache_returns_true_by_default(): void $reflection = new \ReflectionClass($handler); $method = $reflection->getMethod('shouldClearOpcodeCache'); - $method->setAccessible(true); $this->assertTrue($method->invoke($handler)); } @@ -25,7 +26,7 @@ public function test_should_clear_opcache_returns_configured_value(): void { $extension = Mockery::mock(SwooleExtension::class); $workerState = Mockery::mock(WorkerState::class); - $basePath = realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel'); + $basePath = default_skeleton_path(); // Mock the OnWorkerStart handler to test just the shouldClearOpcodeCache method $handler = Mockery::mock(OnWorkerStart::class, [ @@ -41,7 +42,6 @@ public function test_should_clear_opcache_returns_configured_value(): void $reflection = new \ReflectionClass($handler); $method = $reflection->getMethod('shouldClearOpcodeCache'); - $method->setAccessible(true); $this->assertFalse($method->invoke($handler)); } diff --git a/tests/RoadRunnerClientTest.php b/tests/RoadRunnerClientTest.php index b484c01c7..f28a84c9c 100644 --- a/tests/RoadRunnerClientTest.php +++ b/tests/RoadRunnerClientTest.php @@ -34,7 +34,7 @@ public function test_marshal_request_method_marshals_proper_illuminate_request() $this->assertEquals('Taylor', $request->query('name')); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_response_to_roadrunner() { $client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class)); @@ -49,7 +49,7 @@ public function test_respond_method_send_response_to_roadrunner() ]), new OctaneResponse(new Response('Hello World', 200))); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_streamed_response_to_roadrunner() { $client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class)); @@ -66,7 +66,7 @@ public function test_respond_method_send_streamed_response_to_roadrunner() }, 200))); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_streamed_generator_response_to_roadrunner() { $client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class)); @@ -92,7 +92,7 @@ public function test_respond_method_send_streamed_generator_response_to_roadrunn ]), new OctaneResponse(new StreamedResponse($responseCallback, 200))); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_error_method_sends_error_response_to_roadrunner() { $psr7Client = Mockery::mock(PSR7Worker::class); @@ -108,7 +108,7 @@ public function test_error_method_sends_error_response_to_roadrunner() $client->error(new Exception('Something went wrong...'), $app, $request, $context); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_error_method_sends_detailed_error_response_to_roadrunner_in_debug_mode() { $e = new Exception('Something went wrong...'); diff --git a/tests/RoadRunnerServerProcessInspectorTest.php b/tests/RoadRunnerServerProcessInspectorTest.php index 2d51c2541..bc99cd5ec 100644 --- a/tests/RoadRunnerServerProcessInspectorTest.php +++ b/tests/RoadRunnerServerProcessInspectorTest.php @@ -47,7 +47,7 @@ public function test_can_determine_if_roadrunner_server_process_is_running_when_ $processIdFile->delete(); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_roadrunner_server_process_can_be_reloaded() { $this->createApplication(); diff --git a/tests/SwooleClientTest.php b/tests/SwooleClientTest.php index b4eca928c..c4d847c43 100644 --- a/tests/SwooleClientTest.php +++ b/tests/SwooleClientTest.php @@ -133,7 +133,7 @@ public function test_cant_serve_static_files_if_file_has_forbidden_extension(): $this->assertFalse($client->canServeRequestAsStaticFile($request, $context)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_static_file_can_be_served(): void { $client = new SwooleClient; @@ -153,7 +153,7 @@ public function test_static_file_can_be_served(): void $client->serveStaticFile($request, $context); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_static_file_headers_can_be_sent(): void { $this->createApplication(); @@ -209,7 +209,7 @@ public function test_cant_serve_static_files_through_symlink_using_directory_tra $this->assertFalse($client->canServeRequestAsStaticFile($request, $context)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_sends_response_to_swoole(): void { $this->createApplication(); @@ -241,7 +241,7 @@ public function test_respond_method_sends_response_to_swoole(): void ]), new OctaneResponse($response)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_streamed_response_to_swoole(): void { $this->createApplication(); @@ -263,7 +263,7 @@ public function test_respond_method_send_streamed_response_to_swoole(): void }, 200, ['Content-Type' => 'text/html']))); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_with_laravel_specific_status_code_sends_response_to_swoole(): void { $this->createApplication(); @@ -283,7 +283,7 @@ public function test_respond_method_with_laravel_specific_status_code_sends_resp ]), new OctaneResponse(new Response('Hello World', 419, ['Content-Type' => 'text/html']))); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_error_method_sends_error_response_to_swoole(): void { $client = new SwooleClient; @@ -303,7 +303,7 @@ public function test_error_method_sends_error_response_to_swoole(): void $swooleResponse->shouldHaveReceived('end')->with('Internal server error.'); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_error_method_sends_detailed_error_response_to_swoole_in_debug_mode(): void { $client = new SwooleClient; @@ -323,7 +323,7 @@ public function test_error_method_sends_detailed_error_response_to_swoole_in_deb $swooleResponse->shouldHaveReceived('end')->with((string) $e); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_not_chunked_response_to_swoole(): void { $this->createApplication(); @@ -345,7 +345,7 @@ public function test_respond_method_send_not_chunked_response_to_swoole(): void ]), new OctaneResponse($response)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_send_chunked_response_to_swoole(): void { $this->createApplication(); @@ -368,7 +368,7 @@ public function test_respond_method_send_chunked_response_to_swoole(): void ]), new OctaneResponse($response)); } - /** @doesNotPerformAssertions @test */ + /** @test */ public function test_respond_method_preserves_header_formatting_if_configured(): void { $this->createApplication(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 4565304fe..1845a14cd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,9 +3,6 @@ namespace Laravel\Octane\Tests; use Carbon\Laravel\ServiceProvider as CarbonServiceProvider; -use Illuminate\Container\Container; -use Illuminate\Foundation\Bootstrap\HandleExceptions; -use Illuminate\Support\Facades\Facade; use Laravel\Octane\ApplicationFactory; use Laravel\Octane\Contracts\Client; use Laravel\Octane\Octane; @@ -14,14 +11,17 @@ use Laravel\Octane\Testing\Fakes\FakeClient; use Laravel\Octane\Testing\Fakes\FakeWorker; use Mockery; +use Orchestra\Testbench\Concerns\InteractsWithMockery; +use Orchestra\Testbench\Foundation\Application as Testbench; use PHPUnit\Framework\TestCase as BaseTestCase; use Swoole\Table; use function Orchestra\Testbench\default_skeleton_path; -use function Orchestra\Testbench\laravel_version_compare; class TestCase extends BaseTestCase { + use InteractsWithMockery; + protected function createOctaneContext(array $requests) { $appFactory = Mockery::mock(ApplicationFactory::class); @@ -66,7 +66,7 @@ protected function createSwooleTable() protected function appFactory() { - return new ApplicationFactory(realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel')); + return new ApplicationFactory(default_skeleton_path()); } protected function config() @@ -76,19 +76,10 @@ protected function config() protected function tearDown(): void { - parent::tearDown(); - - if (laravel_version_compare('11.0', '>=')) { - HandleExceptions::flushState(); - } else { - HandleExceptions::forgetApp(); - } + Testbench::flushState($this); - Container::setInstance(null); + $this->tearDownTheTestEnvironmentUsingMockery(); - Facade::clearResolvedInstances(); - Facade::setFacadeApplication(null); - - Mockery::close(); + parent::tearDown(); } }