- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
149 lines
4.9 KiB
PHP
149 lines
4.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Framework\Logging;
|
|
|
|
use App\Framework\Logging\ChannelLogger;
|
|
use App\Framework\Logging\DefaultChannelLogger;
|
|
use App\Framework\Logging\LogChannel;
|
|
use App\Framework\Logging\Logger;
|
|
use App\Framework\Logging\LogLevel;
|
|
use App\Framework\Logging\ValueObjects\LogContext;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class DefaultChannelLoggerTest extends TestCase
|
|
{
|
|
private Logger $mockLogger;
|
|
|
|
private ChannelLogger $channelLogger;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->mockLogger = $this->createMock(Logger::class);
|
|
$this->channelLogger = new DefaultChannelLogger($this->mockLogger, LogChannel::SECURITY);
|
|
}
|
|
|
|
public function test_implements_channel_logger_interface(): void
|
|
{
|
|
expect($this->channelLogger)->toBeInstanceOf(ChannelLogger::class);
|
|
}
|
|
|
|
public function test_can_get_channel(): void
|
|
{
|
|
expect($this->channelLogger->getChannel())->toBe(LogChannel::SECURITY);
|
|
}
|
|
|
|
public function test_debug_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::DEBUG, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->debug('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_info_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::INFO, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->info('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_warning_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::WARNING, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->warning('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_error_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::ERROR, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->error('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_critical_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::CRITICAL, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->critical('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_alert_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::ALERT, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->alert('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_emergency_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::EMERGENCY, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->emergency('Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_log_delegates_to_parent_logger(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::WARNING, 'Test message', ['key' => 'value']);
|
|
|
|
$this->channelLogger->log(LogLevel::WARNING, 'Test message', ['key' => 'value']);
|
|
}
|
|
|
|
public function test_supports_log_context_objects(): void
|
|
{
|
|
$logContext = LogContext::withData(['user_id' => 123]);
|
|
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::INFO, 'Test message', $logContext);
|
|
|
|
$this->channelLogger->info('Test message', $logContext);
|
|
}
|
|
|
|
public function test_supports_empty_context(): void
|
|
{
|
|
$this->mockLogger
|
|
->expects($this->once())
|
|
->method('logToChannel')
|
|
->with(LogChannel::SECURITY, LogLevel::INFO, 'Test message', []);
|
|
|
|
$this->channelLogger->info('Test message');
|
|
}
|
|
|
|
public function test_different_channels_work_independently(): void
|
|
{
|
|
$cacheLogger = new DefaultChannelLogger($this->mockLogger, LogChannel::CACHE);
|
|
$dbLogger = new DefaultChannelLogger($this->mockLogger, LogChannel::DATABASE);
|
|
|
|
expect($cacheLogger->getChannel())->toBe(LogChannel::CACHE);
|
|
expect($dbLogger->getChannel())->toBe(LogChannel::DATABASE);
|
|
expect($this->channelLogger->getChannel())->toBe(LogChannel::SECURITY);
|
|
}
|
|
}
|