51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Services\DataBase\Classes\Profiler;
|
|
|
|
class ProfilerTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
// Другие тесты (PdoDriverTest/StatementTest/RepositoryTest) пишут в этот же
|
|
// статический реестр, если есть живое подключение к БД — сбрасываем перед своими тестами.
|
|
Profiler::reset();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Profiler::reset();
|
|
}
|
|
|
|
public function testLogAddsEntry(): void
|
|
{
|
|
Profiler::log('SELECT 1', [], 1.5);
|
|
$entries = Profiler::entries();
|
|
|
|
$this->assertCount(1, $entries);
|
|
$this->assertSame('SELECT 1', $entries[0]['sql']);
|
|
$this->assertSame(1.5, $entries[0]['time_ms']);
|
|
$this->assertSame('pdo', $entries[0]['driver']);
|
|
}
|
|
|
|
public function testCountAndTotalTime(): void
|
|
{
|
|
Profiler::log('SELECT 1', [], 1.0);
|
|
Profiler::log('SELECT 2', [], 2.5);
|
|
|
|
$this->assertSame(2, Profiler::count());
|
|
$this->assertSame(3.5, Profiler::totalTime());
|
|
}
|
|
|
|
public function testResetClearsEntries(): void
|
|
{
|
|
Profiler::log('SELECT 1', [], 1.0);
|
|
Profiler::reset();
|
|
|
|
$this->assertSame(0, Profiler::count());
|
|
$this->assertSame([], Profiler::entries());
|
|
}
|
|
}
|