Files
oficial/app/tests/unit/common/Implement/Log/Handler/MySQLTest.php
Juan Pablo Vial a0723201aa Reorganization
2025-09-15 13:02:44 -03:00

60 lines
1.8 KiB
PHP

<?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);
}
}