Skip to content

Commit 982697a

Browse files
committed
Update logger tests and remove unused config file
- Modified LoggerConfigurationTest.php to improve test coverage - Updated LoggerFactoryTest.php for consistency with recent changes - Deleted unused test_config.php file These changes enhance the test suite for the logging system, ensuring better coverage and removing redundant files.
1 parent f06043b commit 982697a

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

tests/Logger/LoggerConfigurationTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,43 @@ public function testGetWithDefault(): void
3131
public function testLoad(): void
3232
{
3333
$configFile = __DIR__ . '/test_config.php';
34-
file_put_contents($configFile, "<?php return ['key' => 'value'];");
34+
$configContent = <<<PHP
35+
<?php
36+
return [
37+
'default' => 'file',
38+
'channels' => [
39+
'file' => [
40+
'handlers' => ['file'],
41+
],
42+
],
43+
'handlers' => [
44+
'file' => [
45+
'class' => \KaririCode\Logging\Handler\FileHandler::class,
46+
'with' => [
47+
'filePath' => '/path/to/logs/file.log',
48+
],
49+
],
50+
],
51+
'processors' => [],
52+
'formatters' => [
53+
'line' => [
54+
'class' => \KaririCode\Logging\Formatter\LineFormatter::class,
55+
'with' => [
56+
'dateFormat' => 'Y-m-d H:i:s',
57+
],
58+
],
59+
],
60+
];
61+
PHP;
62+
file_put_contents($configFile, $configContent);
3563

3664
$this->config->load($configFile);
37-
$this->assertEquals('value', $this->config->get('key'));
65+
66+
$this->assertEquals('file', $this->config->get('default'));
67+
$this->assertIsArray($this->config->get('channels'));
68+
$this->assertIsArray($this->config->get('handlers'));
69+
$this->assertIsArray($this->config->get('processors'));
70+
$this->assertIsArray($this->config->get('formatters'));
3871

3972
unlink($configFile);
4073
}

tests/Logger/LoggerFactoryTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class LoggerFactoryTest extends TestCase
2525

2626
protected function setUp(): void
2727
{
28+
/** @var LoggerConfiguration */
2829
$this->config = $this->createMock(LoggerConfiguration::class);
30+
/** @var LoggerHandlerFactory */
2931
$this->handlerFactory = $this->createMock(LoggerHandlerFactory::class);
32+
/** @var LoggerProcessorFactory */
3033
$this->processorFactory = $this->createMock(LoggerProcessorFactory::class);
34+
/** @var LoggerFormatterFactory */
3135
$this->formatterFactory = $this->createMock(LoggerFormatterFactory::class);
3236

3337
$this->loggerFactory = new LoggerFactory(
@@ -111,10 +115,14 @@ public function testCreateErrorLogger(): void
111115

112116
public function testCreateAsyncLogger(): void
113117
{
118+
/** @var Logger */
114119
$baseLogger = $this->createMock(Logger::class);
115120
$batchSize = 10;
116121

117-
$asyncLogger = $this->loggerFactory->createAsyncLogger($baseLogger, $batchSize);
122+
$asyncLogger = $this->loggerFactory->createAsyncLogger(
123+
$baseLogger,
124+
$batchSize
125+
);
118126

119127
$this->assertInstanceOf(AsyncLogger::class, $asyncLogger);
120128
}

tests/Logger/test_config.php

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)