remotelyliving /
php-command-bus
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace RemotelyLiving\PHPCommandBus\Tests\Unit\Traits; |
||
| 6 | |||
| 7 | use Psr\Log; |
||
| 8 | use RemotelyLiving\PHPCommandBus\Tests; |
||
| 9 | use RemotelyLiving\PHPCommandBus\Traits; |
||
| 10 | |||
| 11 | class LoggerTest extends Tests\Unit\AbstractTestCase |
||
| 12 | { |
||
| 13 | private Log\Test\TestLogger $testLogger; |
||
| 14 | |||
| 15 | private Log\LoggerAwareInterface $loggableClass; |
||
| 16 | |||
| 17 | protected function setUp(): void |
||
| 18 | { |
||
| 19 | $this->testLogger = $this->createTestLogger(); |
||
| 20 | $this->loggableClass = new class implements Log\LoggerAwareInterface { |
||
| 21 | use Traits\Logger; |
||
| 22 | |||
| 23 | public function getTraitLogger(): Log\LoggerInterface |
||
| 24 | { |
||
| 25 | return $this->getLogger(); |
||
| 26 | } |
||
| 27 | }; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function testDefaultLoggerIsNullLogger(): void |
||
| 31 | { |
||
| 32 | $this->assertInstanceOf(Log\NullLogger::class, $this->loggableClass->getTraitLogger()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 33 | } |
||
| 34 | |||
| 35 | public function testSetsLogger(): void |
||
| 36 | { |
||
| 37 | $this->loggableClass->setLogger($this->testLogger); |
||
| 38 | $this->assertInstanceOf(Log\Test\TestLogger::class, $this->loggableClass->getTraitLogger()); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function testLogs(): void |
||
| 42 | { |
||
| 43 | $this->loggableClass->setLogger($this->testLogger); |
||
| 44 | $this->loggableClass->getTraitLogger()->log('critical', 'the message', ['the' => 'context']); |
||
| 45 | |||
| 46 | $this->assertSame([ |
||
| 47 | 'level' => 'critical', |
||
| 48 | 'message' => 'the message', |
||
| 49 | 'context' => ['the' => 'context'], |
||
| 50 | ], $this->testLogger->records[0]); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |