-
Notifications
You must be signed in to change notification settings - Fork 1
/
LevelConstraintTest.php
94 lines (82 loc) · 2.33 KB
/
LevelConstraintTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare(strict_types=1);
namespace FR3D\Psr3MessagesAssertions\PhpUnit;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestFailure;
use Psr\Log\LogLevel;
class LevelConstraintTest extends TestCase
{
/**
* @var Constraint
*/
protected $constraint;
protected function setUp()
{
$this->constraint = new LevelConstraint();
}
public function testConstraintDefinition()
{
self::assertCount(1, $this->constraint);
self::assertEquals(
'is a recognized log level (emergency, alert, critical, error, warning, notice, info, debug)',
$this->constraint->toString()
);
}
/**
* @dataProvider validLogLevelProvider
*
* @param string $logLevel
*
* @return void
*/
public function testValidLogLevel($logLevel)
{
self::assertTrue($this->constraint->evaluate($logLevel, '', true));
}
/**
* @dataProvider invalidLogLevelProvider
*
* @param $logLevel
*
* @return void
*/
public function testInvalidLogLevel($logLevel)
{
self::assertFalse($this->constraint->evaluate($logLevel, '', true));
try {
$this->constraint->evaluate($logLevel);
self::fail('Expected ExpectationFailedException to be thrown');
} catch (ExpectationFailedException $e) {
self::assertEquals(
<<<EOF
Failed asserting that '$logLevel' is a recognized log level (emergency, alert, critical, error, warning, notice, info, debug).
EOF
,
TestFailure::exceptionToString($e)
);
}
}
public function validLogLevelProvider()
{
return [
LogLevel::EMERGENCY => ['emergency'],
LogLevel::ALERT => ['alert'],
LogLevel::CRITICAL => ['critical'],
LogLevel::ERROR => ['error'],
LogLevel::WARNING => ['warning'],
LogLevel::NOTICE => ['notice'],
LogLevel::INFO => ['info'],
LogLevel::DEBUG => ['debug'],
];
}
public function invalidLogLevelProvider()
{
return [
'emerg' => ['emerg'],
'crit' => ['crit'],
'err' => ['err'],
];
}
}