Skip to content

Commit 0a07bc6

Browse files
authored
Fix getting clear_opcache config failures (#1037)
* Fix getting clear_opcache config failures * Fix test
1 parent 96c8932 commit 0a07bc6

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/Swoole/Handlers/OnWorkerStart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function streamRequestsToConsole($server)
116116
*/
117117
protected function shouldClearOpcodeCache()
118118
{
119-
return config('octane.swoole.clear_opcache', true);
119+
return $this->serverState['octaneConfig']['swoole']['clear_opcache'] ?? true;
120120
}
121121

122122
/**

tests/OnWorkerStartTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Laravel\Octane\Tests;
44

55
use Laravel\Octane\Swoole\Handlers\OnWorkerStart;
6+
use Laravel\Octane\Swoole\SwooleExtension;
7+
use Laravel\Octane\Swoole\WorkerState;
68
use Mockery;
79

810
class OnWorkerStartTest extends TestCase
911
{
1012
public function test_should_clear_opcache_returns_true_by_default(): void
1113
{
12-
$this->createApplication();
13-
1414
// Mock the OnWorkerStart handler to test just the shouldClearOpcodeCache method
1515
$handler = Mockery::mock(OnWorkerStart::class)->makePartial();
1616

@@ -23,11 +23,21 @@ public function test_should_clear_opcache_returns_true_by_default(): void
2323

2424
public function test_should_clear_opcache_returns_configured_value(): void
2525
{
26-
$app = $this->createApplication();
27-
$app['config']['octane.swoole.clear_opcache'] = false;
26+
$extension = Mockery::mock(SwooleExtension::class);
27+
$workerState = Mockery::mock(WorkerState::class);
28+
$basePath = realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel');
2829

2930
// Mock the OnWorkerStart handler to test just the shouldClearOpcodeCache method
30-
$handler = Mockery::mock(OnWorkerStart::class)->makePartial();
31+
$handler = Mockery::mock(OnWorkerStart::class, [
32+
$extension,
33+
$basePath,
34+
['octaneConfig' => [
35+
'swoole' => [
36+
'clear_opcache' => false,
37+
],
38+
]],
39+
$workerState,
40+
])->makePartial();
3141

3242
$reflection = new \ReflectionClass($handler);
3343
$method = $reflection->getMethod('shouldClearOpcodeCache');

0 commit comments

Comments
 (0)