Skip to content

Commit 68db606

Browse files
authored
Fix buffer error (issue #922) (#923)
* fix buffer error * add test * fix formatting * fix formatting * fix formatting
1 parent b5228f9 commit 68db606

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Worker.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function handle(Request $request, RequestContext $context): void
8585

8686
$output = ob_get_contents();
8787

88-
ob_end_clean();
88+
if (ob_get_level()) {
89+
ob_end_clean();
90+
}
8991

9092
// Here we will actually hand the incoming request to the Laravel application so
9193
// it can generate a response. We'll send this response back to the client so

tests/WorkerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,25 @@ public function test_worker_can_dispatch_ticks_to_application_and_returns_respon
4949

5050
$worker->runTicks();
5151
}
52+
53+
/** @test */
54+
public function test_worker_doesnt_throw_buffer_error()
55+
{
56+
[$app, $worker, $client] = $this->createOctaneContext([
57+
Request::create('/test'),
58+
]);
59+
60+
$app['router']->get('/test', function () {
61+
while (ob_get_level() !== 0) {
62+
ob_end_clean();
63+
}
64+
65+
return 'Test Response';
66+
});
67+
68+
$worker->run();
69+
70+
$this->assertCount(1, $client->responses);
71+
$this->assertEquals('Test Response', $client->responses[0]->getContent());
72+
}
5273
}

0 commit comments

Comments
 (0)