Reorganization
This commit is contained in:
59
app/tests/unit/common/Implement/Log/Handler/MySQLTest.php
Normal file
59
app/tests/unit/common/Implement/Log/Handler/MySQLTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Common\Implement\Log\Handler;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Monolog;
|
||||
use Faker\Factory;
|
||||
use Incoviba\Common\Implement\Log\Handler\MySQL;
|
||||
use Incoviba\Common\Define;
|
||||
|
||||
class MySQLTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected function setUp(): void
|
||||
{
|
||||
$pdo = $this->getMockBuilder(PDO::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$pdo->method('prepare')->willReturn($this->getMockBuilder(PDOStatement::class)->getMock());
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->connection->method('getPDO')->willReturn($pdo);
|
||||
}
|
||||
|
||||
public function testWrite(): void
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$context = [];
|
||||
$extra = [];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$context[$faker->word] = $faker->word;
|
||||
$extra[$faker->word] = $faker->word;
|
||||
}
|
||||
$recordArray = [
|
||||
'message' => 'Test message',
|
||||
'context' => $context,
|
||||
'level' => 100,
|
||||
'level_name' => 'DEBUG',
|
||||
'channel' => $faker->word,
|
||||
'datetime' => DateTimeImmutable::createFromMutable($faker->dateTime()),
|
||||
'extra' => $extra,
|
||||
];
|
||||
$record = new Monolog\LogRecord(
|
||||
$recordArray['datetime'],
|
||||
$recordArray['channel'],
|
||||
Monolog\Level::fromName($recordArray['level_name']),
|
||||
$recordArray['message'],
|
||||
$recordArray['context'],
|
||||
$recordArray['extra']);
|
||||
|
||||
$handler = new MySQL($this->connection);
|
||||
$handler->write($record);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user