-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refreshes log manager container (#910)
* Refreshes log manager container * formatting
- Loading branch information
1 parent
5bbe2c5
commit aa96a8b
Showing
4 changed files
with
58 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Laravel\Octane\Listeners; | ||
|
||
class GiveNewApplicationInstanceToLogManager | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param mixed $event | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if (! $event->sandbox->resolved('log')) { | ||
return; | ||
} | ||
|
||
if (method_exists($log = $event->sandbox->make('log'), 'setApplication')) { | ||
$log->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
34 changes: 34 additions & 0 deletions
34
tests/Listeners/GiveNewApplicationInstanceToLogManagerTest.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,34 @@ | ||
<?php | ||
|
||
namespace Laravel\Octane\Tests\Listeners; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Context; | ||
use Illuminate\Support\Facades\Log; | ||
use Laravel\Octane\Tests\TestCase; | ||
|
||
class GiveNewApplicationInstanceToLogManagerTest extends TestCase | ||
{ | ||
public function test_context_is_appened_to_logs() | ||
{ | ||
if (! class_exists(Context::class)) { | ||
$this->markTestSkipped('Context is not available in this version of Laravel.'); | ||
} | ||
[$app, $worker, $client] = $this->createOctaneContext([ | ||
Request::create('/', 'GET'), | ||
]); | ||
$path = $app['config']->get('logging.channels.single.path'); | ||
@unlink($path); | ||
|
||
$this->assertFileDoesNotExist($path); | ||
|
||
$app['router']->middleware('web')->get('/', function () { | ||
Context::add('foo', 'bar'); | ||
Log::info('Hello world'); | ||
}); | ||
|
||
$worker->run(); | ||
|
||
$this->assertStringContainsString('{"foo":"bar"}', file_get_contents($path)); | ||
} | ||
} |