Files
michaelschiemer/tests/Unit/Framework/Logging/MetricsCollectorTest.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
2025-10-25 19:18:37 +02:00

103 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Framework\Logging;
use App\Framework\Logging\LogLevel;
use App\Framework\Logging\Metrics\LogMetricsCollector;
use PHPUnit\Framework\TestCase;
final class MetricsCollectorTest extends TestCase
{
protected function tearDown(): void
{
LogMetricsCollector::resetInstance();
}
public function test_tracks_log_counts(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::ERROR, 'app');
$collector->recordLog(LogLevel::ERROR, 'api');
$metrics = $collector->getMetrics();
$this->assertEquals(3, $metrics->getTotalLogs());
$this->assertEquals(2, $metrics->getErrorCount());
}
public function test_calculates_error_rate(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::ERROR, 'app');
$metrics = $collector->getMetrics();
$this->assertEquals(1 / 3, $metrics->getErrorRate());
}
public function test_tracks_by_level(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::ERROR, 'app');
$metrics = $collector->getMetrics();
$byLevel = $metrics->getCountsByLevel();
$this->assertEquals(2, $byLevel['INFO']);
$this->assertEquals(1, $byLevel['ERROR']);
}
public function test_tracks_by_channel(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::INFO, 'api');
$collector->recordLog(LogLevel::INFO, 'api');
$metrics = $collector->getMetrics();
$byChannel = $metrics->getCountsByChannel();
$this->assertEquals(1, $byChannel['app']);
$this->assertEquals(2, $byChannel['api']);
}
public function test_resets_metrics(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->reset();
$metrics = $collector->getMetrics();
$this->assertEquals(0, $metrics->getTotalLogs());
}
public function test_provides_summary(): void
{
$collector = LogMetricsCollector::getInstance();
$collector->recordLog(LogLevel::INFO, 'app');
$collector->recordLog(LogLevel::ERROR, 'app');
$summary = $collector->getSummary();
$this->assertArrayHasKey('total', $summary);
$this->assertArrayHasKey('errors', $summary);
$this->assertArrayHasKey('error_rate', $summary);
$this->assertArrayHasKey('uptime_seconds', $summary);
$this->assertArrayHasKey('logs_per_second', $summary);
}
}