Skip to content

Commit

Permalink
Fix FilesystemManager app instance (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist authored Jan 6, 2022
1 parent 62cf8d5 commit 2eba7a8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"php": "^8.0",
"laravel/framework": "^8.70",
"laravel/framework": "^8.77",
"laminas/laminas-diactoros": "^2.5",
"laravel/serializable-closure": "^1.0",
"symfony/psr-http-message-bridge": "^2.0"
Expand Down
1 change: 1 addition & 0 deletions src/Concerns/ProvidesDefaultConfigurationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function prepareApplicationForNextOperation(): array
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseSessionHandler::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToFilesystemManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class,
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class,
Expand Down
23 changes: 23 additions & 0 deletions src/Listeners/GiveNewApplicationInstanceToFilesystemManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Octane\Listeners;

class GiveNewApplicationInstanceToFilesystemManager
{
/**
* Handle the event.
*
* @param mixed $event
* @return void
*/
public function handle($event): void
{
if (! $event->sandbox->resolved('filesystem')) {
return;
}

with($event->sandbox->make('filesystem'), function ($manager) use ($event) {
$manager->setApplication($event->sandbox);
});
}
}
28 changes: 28 additions & 0 deletions tests/FilesystemManagerStateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Laravel\Octane\Tests;

use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use ReflectionProperty;

class FilesystemManagerStateTest extends TestCase
{
public function test_filesystem_manager_has_fresh_application_instance()
{
[$app, $worker, $client] = $this->createOctaneContext([
Request::create('/first', 'GET'),
Request::create('/first', 'GET'),
]);

$filesystemManagerApplication = new ReflectionProperty($app['filesystem'], 'app');

$app['router']->get('/first', function (Application $app) use ($filesystemManagerApplication) {
return spl_object_hash($filesystemManagerApplication->getValue($app['filesystem']));
});

$worker->run();

$this->assertNotEquals($client->responses[0]->original, $client->responses[1]->original);
}
}

0 comments on commit 2eba7a8

Please sign in to comment.