-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from spiral/bugfix/monolog-bubble
[spiral/monolog-bridge] Set `bubble` as `true` by default in logRotate method
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 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 |
---|---|---|
|
@@ -33,6 +33,6 @@ public function handle(array $record): bool | |
$listener($e); | ||
} | ||
|
||
return true; | ||
return false === $this->bubble; | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Monolog; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Spiral\Logger\Event\LogEvent; | ||
use Spiral\Logger\ListenerRegistry; | ||
use Spiral\Monolog\EventHandler; | ||
|
||
final class EventHandlerTest extends TestCase | ||
{ | ||
private ListenerRegistry $registry; | ||
private object $listener; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->listener = new class() { | ||
public LogEvent $event; | ||
|
||
public function __invoke(LogEvent $event): void | ||
{ | ||
$this->event = $event; | ||
} | ||
}; | ||
|
||
$this->registry = new ListenerRegistry(); | ||
$this->registry->addListener($this->listener); | ||
} | ||
|
||
public function testHandle(): void | ||
{ | ||
$handler = new EventHandler($this->registry); | ||
|
||
$result = $handler->handle([ | ||
'datetime' => new \DateTimeImmutable(), | ||
'channel' => 'foo', | ||
'level' => 100, | ||
'message' => 'bar', | ||
'context' => ['foo' => 'bar'], | ||
]); | ||
|
||
$this->assertSame('foo', $this->listener->event->getChannel()); | ||
$this->assertSame('bar', $this->listener->event->getMessage()); | ||
$this->assertSame(['foo' => 'bar'], $this->listener->event->getContext()); | ||
$this->assertSame('debug', $this->listener->event->getLevel()); | ||
$this->assertFalse($result); | ||
} | ||
|
||
public function testHandleWithBubbleFalse(): void | ||
{ | ||
$handler = new EventHandler(listenerRegistry: $this->registry, bubble: false); | ||
|
||
$result = $handler->handle([ | ||
'datetime' => new \DateTimeImmutable(), | ||
'channel' => 'foo', | ||
'level' => 100, | ||
'message' => 'bar', | ||
'context' => ['foo' => 'bar'], | ||
]); | ||
|
||
$this->assertSame('foo', $this->listener->event->getChannel()); | ||
$this->assertSame('bar', $this->listener->event->getMessage()); | ||
$this->assertSame(['foo' => 'bar'], $this->listener->event->getContext()); | ||
$this->assertSame('debug', $this->listener->event->getLevel()); | ||
$this->assertTrue($result); | ||
} | ||
} |
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