Skip to content

Commit cb753f9

Browse files
authored
Merge pull request #16 from abacaphiliac/coverage
increase coverage
2 parents 0bf991b + cdc48b2 commit cb753f9

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

test/LogLevelConfigurationTest.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace AbacaphiliacTest\Doctrine;
4+
5+
use Abacaphiliac\Doctrine\LogLevelConfiguration;
6+
use InvalidArgumentException;
7+
use PHPUnit\Framework\TestCase;
8+
use Psr\Log\LogLevel;
9+
10+
/**
11+
* @covers \Abacaphiliac\Doctrine\LogLevelConfiguration
12+
*/
13+
class LogLevelConfigurationTest extends TestCase
14+
{
15+
/** @var LogLevelConfiguration */
16+
private $sut;
17+
18+
protected function setUp()
19+
{
20+
$this->sut = new LogLevelConfiguration([
21+
LogLevel::DEBUG => 0,
22+
LogLevel::INFO => 10,
23+
LogLevel::NOTICE => 20,
24+
LogLevel::WARNING => 30,
25+
LogLevel::ERROR => 40,
26+
LogLevel::CRITICAL => 50,
27+
LogLevel::ALERT => 60,
28+
LogLevel::EMERGENCY => 70,
29+
]);
30+
}
31+
32+
public static function dataValidLevels(): array
33+
{
34+
return [
35+
[-1, null],
36+
[0, null],
37+
[1, LogLevel::DEBUG],
38+
[9, LogLevel::DEBUG],
39+
[10, LogLevel::INFO],
40+
[11, LogLevel::INFO],
41+
[19, LogLevel::INFO],
42+
[20, LogLevel::NOTICE],
43+
[21, LogLevel::NOTICE],
44+
[29, LogLevel::NOTICE],
45+
[30, LogLevel::WARNING],
46+
[31, LogLevel::WARNING],
47+
[39, LogLevel::WARNING],
48+
[40, LogLevel::ERROR],
49+
[41, LogLevel::ERROR],
50+
[49, LogLevel::ERROR],
51+
[50, LogLevel::CRITICAL],
52+
[51, LogLevel::CRITICAL],
53+
[59, LogLevel::CRITICAL],
54+
[60, LogLevel::ALERT],
55+
[61, LogLevel::ALERT],
56+
[69, LogLevel::ALERT],
57+
[70, LogLevel::EMERGENCY],
58+
[71, LogLevel::EMERGENCY],
59+
[79, LogLevel::EMERGENCY],
60+
];
61+
}
62+
63+
/**
64+
* @dataProvider dataValidLevels
65+
* @param float $durationMs
66+
* @param string | null $expected
67+
*/
68+
public function testValidLevels(
69+
float $durationMs,
70+
?string $expected
71+
): void {
72+
$actual = $this->sut->getApplicableLogLevel($durationMs / 1000);
73+
74+
self::assertSame($expected, $actual);
75+
}
76+
77+
public function testInvalidLogLevel(): void
78+
{
79+
self::expectException(InvalidArgumentException::class);
80+
self::expectExceptionMessage('invalid LogLevel detected: "InvalidLevel", please choose from: "' . print_r([
81+
'EMERGENCY' => 'emergency',
82+
'ALERT' => 'alert',
83+
'CRITICAL' => 'critical',
84+
'ERROR' => 'error',
85+
'WARNING' => 'warning',
86+
'NOTICE' => 'notice',
87+
'INFO' => 'info',
88+
'DEBUG' => 'debug',
89+
], true) . '"');
90+
91+
new LogLevelConfiguration([
92+
'InvalidLevel' => 1000,
93+
]);
94+
}
95+
}

test/PsrSqlLoggerConfigurableLogLevelsTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Abacaphiliac\Doctrine\LogLevelConfiguration;
66
use Abacaphiliac\Doctrine\PsrSqlLoggerConfigurableLogLevels;
7+
use Psr\Log\LoggerInterface;
78
use Psr\Log\Test\TestLogger;
89
use InvalidArgumentException;
910
use PHPUnit\Framework\TestCase;
@@ -13,7 +14,7 @@
1314
use function usleep;
1415

1516
/**
16-
* @covers \Abacaphiliac\Doctrine\PsrSqlLogger
17+
* @covers \Abacaphiliac\Doctrine\PsrSqlLoggerConfigurableLogLevels
1718
*/
1819
class PsrSqlLoggerConfigurableLogLevelsTest extends TestCase
1920
{
@@ -118,6 +119,53 @@ public function testInvalidLogLevelUsedInConfiguration() : void
118119
);
119120
}
120121

122+
public function testInvalidDefaultLogLevel() : void
123+
{
124+
$this->expectException(InvalidArgumentException::class);
125+
new PsrSqlLoggerConfigurableLogLevels(
126+
new class implements LoggerInterface {
127+
public function emergency($message, array $context = array())
128+
{
129+
}
130+
131+
public function alert($message, array $context = array())
132+
{
133+
}
134+
135+
public function critical($message, array $context = array())
136+
{
137+
}
138+
139+
public function error($message, array $context = array())
140+
{
141+
}
142+
143+
public function warning($message, array $context = array())
144+
{
145+
}
146+
147+
public function notice($message, array $context = array())
148+
{
149+
}
150+
151+
public function info($message, array $context = array())
152+
{
153+
}
154+
155+
public function debug($message, array $context = array())
156+
{
157+
}
158+
159+
public function log($level, $message, array $context = array())
160+
{
161+
}
162+
},
163+
new LogLevelConfiguration([
164+
]),
165+
'InvalidLevel'
166+
);
167+
}
168+
121169
protected function setUp()
122170
{
123171
$this->logger = new TestLogger();

0 commit comments

Comments
 (0)