-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.x] Adds Laravel 10 support (#146)
* Adds Laravel 10 support * Adds support for monolog `^3.2` * Improves tests around monolog * Don't use PHPUnit 10 * Update composer.json Co-authored-by: Joe Dixon <joedixon@users.noreply.github.com> * Tests Octane on Laravel 10 Co-authored-by: Joe Dixon <joedixon@users.noreply.github.com>
- Loading branch information
1 parent
323cd74
commit 170a1f4
Showing
5 changed files
with
189 additions
and
26 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
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
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,147 @@ | ||
<?php | ||
|
||
namespace Laravel\Vapor\Tests\Unit\Logging; | ||
|
||
use Laravel\Vapor\Logging\JsonFormatter; | ||
use Mockery; | ||
use Monolog\Level; | ||
use Monolog\LogRecord; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class JsonFormatterTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
Mockery::close(); | ||
|
||
unset($_ENV['AWS_REQUEST_ID']); | ||
} | ||
|
||
public function test_format() | ||
{ | ||
$formatter = new JsonFormatter(); | ||
|
||
if (class_exists(LogRecord::class)) { | ||
$record = new LogRecord( | ||
new \DateTimeImmutable(), | ||
'channel-test', | ||
Level::Info, | ||
'message-test', | ||
['context-test' => 'context-value'], | ||
['extra-test' => 'extra-value'] | ||
); | ||
} else { | ||
$record = [ | ||
'datetime' => new \DateTimeImmutable(), | ||
'channel' => 'channel-test', | ||
'level' => 200, | ||
'level_name' => 'INFO', | ||
'message' => 'message-test', | ||
'context' => ['context-test' => 'context-value'], | ||
'extra' => ['extra-test' => 'extra-value'], | ||
]; | ||
} | ||
|
||
$_ENV['AWS_REQUEST_ID'] = '123456789'; | ||
|
||
$record = $formatter->format($record); | ||
$this->assertJson($record); | ||
|
||
$record = json_decode($record, true); | ||
|
||
if (class_exists(LogRecord::class)) { | ||
$this->assertSame([ | ||
'message' => 'message-test', | ||
'context' => [ | ||
'context-test' => 'context-value', | ||
'aws_request_id' => '123456789', | ||
], | ||
'level' => 200, | ||
'level_name' => 'INFO', | ||
'channel' => 'channel-test', | ||
'datetime' => $record['datetime'], | ||
'extra' => [ | ||
'extra-test' => 'extra-value', | ||
], | ||
], $record); | ||
} else { | ||
$this->assertSame([ | ||
'datetime' => $record['datetime'], | ||
'channel' => 'channel-test', | ||
'level' => 200, | ||
'level_name' => 'INFO', | ||
'message' => 'message-test', | ||
'context' => [ | ||
'context-test' => 'context-value', | ||
'aws_request_id' => '123456789', | ||
], | ||
'extra' => [ | ||
'extra-test' => 'extra-value', | ||
], | ||
], $record); | ||
} | ||
} | ||
|
||
public function test_includes_aws_request_id() | ||
{ | ||
$formatter = new JsonFormatter(); | ||
|
||
$_ENV['AWS_REQUEST_ID'] = '123456789'; | ||
|
||
if (class_exists(LogRecord::class)) { | ||
$record = new LogRecord( | ||
new \DateTimeImmutable(), | ||
'channel-test', | ||
Level::Info, | ||
'message-test', | ||
['foo' => 'bar'] | ||
); | ||
} else { | ||
$record = [ | ||
'datetime' => new \DateTimeImmutable(), | ||
'channel' => 'channel-test', | ||
'level' => 200, | ||
'level_name' => 'INFO', | ||
'message' => 'message-test', | ||
'context' => ['foo' => 'bar'], | ||
'extra' => [], | ||
]; | ||
} | ||
|
||
$record = $formatter->format($record); | ||
$this->assertJson($record); | ||
|
||
$record = json_decode($record, true); | ||
$this->assertSame(['foo' => 'bar', 'aws_request_id' => '123456789'], $record['context']); | ||
} | ||
|
||
public function test_aws_request_id_may_be_null() | ||
{ | ||
$formatter = new JsonFormatter(); | ||
|
||
if (class_exists(LogRecord::class)) { | ||
$record = new LogRecord( | ||
new \DateTimeImmutable(), | ||
'channel-test', | ||
Level::Info, | ||
'message-test' | ||
); | ||
} else { | ||
$record = [ | ||
'datetime' => new \DateTimeImmutable(), | ||
'channel' => 'channel-test', | ||
'level' => 200, | ||
'level_name' => 'INFO', | ||
'message' => 'message-test', | ||
'context' => [], | ||
'extra' => [], | ||
]; | ||
} | ||
|
||
$record = $formatter->format($record); | ||
$this->assertJson($record); | ||
|
||
$record = json_decode($record, true); | ||
$this->assertSame(['aws_request_id' => null], $record['context']); | ||
} | ||
} |