Skip to content

Commit

Permalink
Add UuidProcessor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Nov 7, 2023
1 parent b66962c commit 6428867
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions tests/UuidProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* file that was distributed with this source code.
*/


use Monolog\Handler\TestHandler;
use Monolog\Level;
use MonologProcessorCollection\Tests\AbstractProcessorTestCase;
Expand All @@ -22,14 +21,46 @@ public function testItWorks(): void
{
$processor = new UuidProcessor();

$handler = new TestHandler();
$handler->pushProcessor($processor);
$handler->handle($this->createRecord(Level::Notice));
$handler->handle($this->createRecord(Level::Notice));

$this->assertTrue($handler->hasNoticeRecords());
$firstRecord = $handler->getRecords()[0];
$secondRecord = $handler->getRecords()[1];

$this->assertArrayHasKey('uuid', $firstRecord->extra);
$this->assertTrue(Uuid::isValid($firstRecord->extra['uuid']));

$this->assertArrayHasKey('uuid', $secondRecord->extra);
$this->assertTrue(Uuid::isValid($secondRecord->extra['uuid']));

$this->assertSame($firstRecord->extra['uuid'], $secondRecord->extra['uuid']);
}

public function testResettable(): void
{
$processor = new UuidProcessor();

$handler = new TestHandler();
$handler->pushProcessor($processor);
$handler->handle($this->createRecord(Level::Notice));

$processor->reset();

$handler->handle($this->createRecord(Level::Notice));

$this->assertTrue($handler->hasNoticeRecords());
$record = $handler->getRecords()[0];
$firstRecord = $handler->getRecords()[0];
$secondRecord = $handler->getRecords()[1];

$this->assertArrayHasKey('uuid', $firstRecord->extra);
$this->assertTrue(Uuid::isValid($firstRecord->extra['uuid']));

$this->assertArrayHasKey('uuid', $secondRecord->extra);
$this->assertTrue(Uuid::isValid($secondRecord->extra['uuid']));

$this->assertArrayHasKey('uuid', $record->extra);
$this->assertTrue(Uuid::isValid($record->extra['uuid']));
$this->assertNotSame($firstRecord->extra['uuid'], $secondRecord->extra['uuid']);
}
}

0 comments on commit 6428867

Please sign in to comment.