From 584b6b74032e50b0c9d929d87936913f7d72a7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Pol=C3=A1k?= Date: Fri, 5 Jul 2024 12:08:22 +0200 Subject: [PATCH 1/5] fix buffer error --- src/Worker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Worker.php b/src/Worker.php index d3b1e33d1..c1f740c7b 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -85,7 +85,9 @@ public function handle(Request $request, RequestContext $context): void $output = ob_get_contents(); - ob_end_clean(); + if (ob_get_level()) { + ob_end_clean(); + } // Here we will actually hand the incoming request to the Laravel application so // it can generate a response. We'll send this response back to the client so From 3634e7da23a2d0ddbd2148b73e7b5ef7ee99f397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Pol=C3=A1k?= Date: Fri, 5 Jul 2024 12:49:44 +0200 Subject: [PATCH 2/5] add test --- tests/WorkerTest.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php index 9637a706d..8a9508f08 100644 --- a/tests/WorkerTest.php +++ b/tests/WorkerTest.php @@ -3,6 +3,7 @@ namespace Laravel\Octane\Tests; use Illuminate\Http\Request; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; class WorkerTest extends TestCase { @@ -13,8 +14,8 @@ public function test_worker_can_dispatch_request_to_application_and_returns_resp Request::create('/second', 'GET'), ]); - $app['router']->get('/first', fn () => 'First Response'); - $app['router']->get('/second', fn () => 'Second Response'); + $app['router']->get('/first', fn() => 'First Response'); + $app['router']->get('/second', fn() => 'Second Response'); $worker->run(); @@ -26,8 +27,8 @@ public function test_worker_can_dispatch_request_to_application_and_returns_resp public function test_worker_can_dispatch_task_to_application_and_returns_responses_to_client() { [$app, $worker, $client] = $this->createOctaneContext([ - fn () => 'foo', - fn () => 'bar', + fn() => 'foo', + fn() => 'bar', function () { }, ]); @@ -39,7 +40,7 @@ function () { $this->assertNull($responses[2]->result); } - /** @doesNotPerformAssertions @test */ + /** @doesNotPerformAssertions @test */ public function test_worker_can_dispatch_ticks_to_application_and_returns_responses_to_client() { [$app, $worker, $client] = $this->createOctaneContext([ @@ -49,4 +50,24 @@ public function test_worker_can_dispatch_ticks_to_application_and_returns_respon $worker->runTicks(); } + + /** @test */ + public function test_worker_doesnt_throw_buffer_error() + { + [$app, $worker, $client] = $this->createOctaneContext([ + Request::create('/test'), + ]); + + $app['router']->get('/test', function () { + while (ob_get_level() !== 0) { + ob_end_clean(); + } + return 'Test Response'; + }); + + $worker->run(); + + $this->assertCount(1, $client->responses); + $this->assertEquals('Test Response', $client->responses[0]->getContent()); + } } From ef5a2092b49a715164e89cfece10ec50b4256a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Pol=C3=A1k?= Date: Fri, 5 Jul 2024 12:51:52 +0200 Subject: [PATCH 3/5] fix formatting --- tests/WorkerTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php index 8a9508f08..dc4986f3a 100644 --- a/tests/WorkerTest.php +++ b/tests/WorkerTest.php @@ -3,7 +3,6 @@ namespace Laravel\Octane\Tests; use Illuminate\Http\Request; -use PHPUnit\Framework\Attributes\RunInSeparateProcess; class WorkerTest extends TestCase { @@ -14,8 +13,8 @@ public function test_worker_can_dispatch_request_to_application_and_returns_resp Request::create('/second', 'GET'), ]); - $app['router']->get('/first', fn() => 'First Response'); - $app['router']->get('/second', fn() => 'Second Response'); + $app['router']->get('/first', fn () => 'First Response'); + $app['router']->get('/second', fn () => 'Second Response'); $worker->run(); @@ -27,8 +26,8 @@ public function test_worker_can_dispatch_request_to_application_and_returns_resp public function test_worker_can_dispatch_task_to_application_and_returns_responses_to_client() { [$app, $worker, $client] = $this->createOctaneContext([ - fn() => 'foo', - fn() => 'bar', + fn () => 'foo', + fn () => 'bar', function () { }, ]); From 41610afa1c0ab9ca5c242eab456f4dd51410c213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Pol=C3=A1k?= Date: Fri, 5 Jul 2024 12:53:22 +0200 Subject: [PATCH 4/5] fix formatting --- tests/WorkerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php index dc4986f3a..a7cef3094 100644 --- a/tests/WorkerTest.php +++ b/tests/WorkerTest.php @@ -61,6 +61,7 @@ public function test_worker_doesnt_throw_buffer_error() while (ob_get_level() !== 0) { ob_end_clean(); } + return 'Test Response'; }); From dd8f34ed3238a859b863a8c1eb3068af7d430259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Pol=C3=A1k?= Date: Fri, 5 Jul 2024 13:04:05 +0200 Subject: [PATCH 5/5] fix formatting --- tests/WorkerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php index a7cef3094..813dfabe9 100644 --- a/tests/WorkerTest.php +++ b/tests/WorkerTest.php @@ -39,7 +39,7 @@ function () { $this->assertNull($responses[2]->result); } - /** @doesNotPerformAssertions @test */ + /** @doesNotPerformAssertions @test */ public function test_worker_can_dispatch_ticks_to_application_and_returns_responses_to_client() { [$app, $worker, $client] = $this->createOctaneContext([