-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportingLevelTest.php
187 lines (153 loc) · 4.95 KB
/
ReportingLevelTest.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
declare(strict_types=1);
namespace Bakame\Aide\Error;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use ValueError;
use const E_ALL;
use const E_DEPRECATED;
use const E_NOTICE;
use const E_WARNING;
final class ReportingLevelTest extends TestCase
{
#[Test]
public function it_tells_nothing_is_contains_if_nothing_is_given_to_the_method(): void
{
self::assertFalse(ReportingLevel::fromEnv()->contains());
}
#[Test]
#[DataProvider('provideErrorLevelContains')]
public function it_can_tell_whether_the_error_level_is_contained(int $errorLevel, int|string $test, bool $expected): void
{
self::assertSame($expected, ReportingLevel::fromValue($errorLevel)->contains($test));
}
/**
* @return iterable<string, array{errorLevel:int, test:int|string, expected:bool}>
*/
public static function provideErrorLevelContains(): iterable
{
yield '-1 contains everything (1)' => [
'errorLevel' => -1,
'test' => 0,
'expected' => true,
];
yield '-1 contains everything (2)' => [
'errorLevel' => -1,
'test' => E_ALL | E_WARNING,
'expected' => true,
];
yield '0 contains nothing (1)' => [
'errorLevel' => 0,
'test' => -1,
'expected' => false,
];
yield '0 contains nothing (2)' => [
'errorLevel' => 0,
'test' => E_DEPRECATED | E_NOTICE,
'expected' => false,
];
yield 'union error level (1)' => [
'errorLevel' => E_DEPRECATED | E_NOTICE,
'test' => 'E_DEPRECATED',
'expected' => true,
];
yield 'union error level (2)' => [
'errorLevel' => E_WARNING | E_NOTICE,
'test' => E_NOTICE,
'expected' => true,
];
yield 'exclusion error level (1)' => [
'errorLevel' => E_ALL & ~E_NOTICE,
'test' => E_WARNING,
'expected' => true,
];
yield 'exclusion error level (2)' => [
'errorLevel' => E_ALL & ~E_WARNING,
'test' => E_WARNING,
'expected' => false,
];
}
#[Test]
public function it_can_create_error_level_by_exclusion(): void
{
self::assertSame(
ReportingLevel::fromExclusion(E_WARNING, 'E_WARNING')->value(),
ReportingLevel::fromValue(E_ALL & ~E_WARNING)->value(),
);
}
#[Test]
public function it_can_create_error_level_from_environment(): void
{
self::assertSame(
ReportingLevel::fromEnv()->value(),
ReportingLevel::fromValue(error_reporting())->value(),
);
}
#[Test]
public function it_can_create_error_level_by_inclusion(): void
{
self::assertSame(
ReportingLevel::fromInclusion(E_WARNING, 'E_WARNING')->value(),
ReportingLevel::fromValue(E_WARNING)->value(),
);
}
#[Test]
public function it_fails_to_create_error_level_by_exclusion(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromExclusion(-2, 'E_WARNING')->value();
}
#[Test]
public function it_fails_to_create_error_level_by_inclusion(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromInclusion(-2, 'E_FOOBAR')->value();
}
#[Test]
public function it_can_create_error_level_by_name(): void
{
self::assertSame(
ReportingLevel::fromName('E_WARNING')->value(),
ReportingLevel::fromValue(E_WARNING)->value(),
);
}
#[Test]
public function it_fails_to_create_error_level_by_name(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromName('E_FOOBAR');
}
#[Test]
public function it_fails_to_create_error_level_by_value(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromValue(-2);
}
#[Test]
public function it_fails_to_create_error_level_by_inclusion_with_invalid_positive_integer(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromInclusion(23);
}
#[Test]
public function it_fails_to_create_error_level_by_exclusion_with_invalid_positive_integer(): void
{
$this->expectException(ValueError::class);
ReportingLevel::fromExclusion(23);
}
#[Test]
public function it_can_be_instantiate_from_its_name(): void
{
self::assertEquals(
ReportingLevel::fromInclusion(E_WARNING),
ReportingLevel::warning()
);
}
#[Test]
public function it_can_be_included_or_excluded(): void
{
self::assertSame(['E_ALL', 'E_WARNING'], ReportingLevel::warning()->included());
self::assertSame(['E_WARNING'], ReportingLevel::fromExclusion('E_WARNING')->excluded());
}
}