-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FilesystemManager app instance (#458)
- Loading branch information
1 parent
62cf8d5
commit 2eba7a8
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Listeners/GiveNewApplicationInstanceToFilesystemManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |