Skip to content

Commit 8aef721

Browse files
authored
Merge pull request #437 from Seldaek/monolog3
Allow installing Monolog 3, and run test suite with it
2 parents a0ef658 + 9532d47 commit 8aef721

File tree

7 files changed

+57
-27
lines changed

7 files changed

+57
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
- php: '7.4'
1919
deps: lowest
2020
deprecations: max[self]=0
21+
- php: '8.1'
22+
deps: highest
23+
monolog: '3.*'
2124
steps:
2225
- name: Checkout
2326
uses: actions/checkout@v2

DependencyInjection/Configuration.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,17 +1035,18 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode)
10351035
$verbosity
10361036
));
10371037
}
1038-
if (!is_numeric($level)) {
1039-
$levelConstant = 'Monolog\Logger::'.$level;
1040-
if (!defined($levelConstant)) {
1041-
throw new InvalidConfigurationException(sprintf(
1042-
'The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.',
1043-
$level, $verbosity
1044-
));
1038+
1039+
try {
1040+
if (Logger::API === 3) {
1041+
$level = Logger::toMonologLevel($level)->value;
1042+
} else {
1043+
$level = Logger::toMonologLevel(is_numeric($level) ? (int) $level : $level);
10451044
}
1046-
$level = constant($levelConstant);
1047-
} else {
1048-
$level = (int) $level;
1045+
} catch (\Psr\Log\InvalidArgumentException $e) {
1046+
throw new InvalidConfigurationException(sprintf(
1047+
'The configured minimum log level "%s" for verbosity "%s" is invalid as it is not defined in Monolog\Logger.',
1048+
$level, $verbosity
1049+
));
10491050
}
10501051

10511052
$map[constant($verbosityConstant)] = $level;

DependencyInjection/MonologExtension.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,22 +1032,36 @@ private function getHandlerClassByType($handlerType)
10321032
'slackbot',
10331033
];
10341034

1035-
if (Logger::API === 2) {
1035+
$v3HandlerTypesRemoved = [
1036+
'swift_mailer',
1037+
];
1038+
1039+
if (Logger::API >= 2) {
10361040
$typeToClassMapping = array_merge($typeToClassMapping, $v2HandlerTypesAdded);
10371041
foreach($v2HandlerTypesRemoved as $v2HandlerTypeRemoved) {
10381042
unset($typeToClassMapping[$v2HandlerTypeRemoved]);
10391043
}
10401044
}
10411045

1046+
if (Logger::API >= 3) {
1047+
foreach($v3HandlerTypesRemoved as $v3HandlerTypeRemoved) {
1048+
unset($typeToClassMapping[$v3HandlerTypeRemoved]);
1049+
}
1050+
}
1051+
10421052
if (!isset($typeToClassMapping[$handlerType])) {
10431053
if (Logger::API === 1 && array_key_exists($handlerType, $v2HandlerTypesAdded)) {
10441054
throw new \InvalidArgumentException(sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType));
10451055
}
10461056

1047-
if (Logger::API === 2 && array_key_exists($handlerType, $v2HandlerTypesRemoved)) {
1057+
if (Logger::API >= 2 && array_key_exists($handlerType, $v2HandlerTypesRemoved)) {
10481058
throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v2.', $handlerType));
10491059
}
10501060

1061+
if (Logger::API >= 3 && array_key_exists($handlerType, $v3HandlerTypesRemoved)) {
1062+
throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v3.', $handlerType));
1063+
}
1064+
10511065
throw new \InvalidArgumentException(sprintf('There is no handler class defined for handler "%s".', $handlerType));
10521066
}
10531067

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ public function testMergingInvalidChannels()
191191

192192
public function testWithSwiftMailerHandler()
193193
{
194+
if (\Monolog\Logger::API >= 3) {
195+
$this->markTestSkipped('This test requires Monolog v1 or v2');
196+
}
197+
194198
$configs = [
195199
[
196200
'handlers' => [
@@ -273,7 +277,7 @@ public function testWithConsoleHandler()
273277
'verbosity_levels' => [
274278
'VERBOSITY_NORMAL' => 'NOTICE',
275279
'verbosity_verbose' => 'info',
276-
'VERBOSITY_very_VERBOSE' => 150
280+
'VERBOSITY_very_VERBOSE' => '200'
277281
]
278282
]
279283
]
@@ -286,7 +290,7 @@ public function testWithConsoleHandler()
286290
$this->assertSame([
287291
OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE,
288292
OutputInterface::VERBOSITY_VERBOSE => Logger::INFO,
289-
OutputInterface::VERBOSITY_VERY_VERBOSE => 150,
293+
OutputInterface::VERBOSITY_VERY_VERBOSE => 200,
290294
OutputInterface::VERBOSITY_QUIET => Logger::ERROR,
291295
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG
292296
], $config['handlers']['console']['verbosity_levels']);

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public function testHandlersWithChannels()
184184

185185
public function testSingleEmailRecipient()
186186
{
187+
if (\Monolog\Logger::API >= 3) {
188+
$this->markTestSkipped('This test requires Monolog v1 or v2');
189+
}
190+
187191
$container = $this->getContainer('single_email_recipient');
188192

189193
$this->assertEquals([
@@ -212,6 +216,10 @@ public function testServerLog()
212216

213217
public function testMultipleEmailRecipients()
214218
{
219+
if (\Monolog\Logger::API >= 3) {
220+
$this->markTestSkipped('This test requires Monolog v1 or v2');
221+
}
222+
215223
$container = $this->getContainer('multiple_email_recipients');
216224

217225
$this->assertEquals([
@@ -249,7 +257,7 @@ public function testPsr3MessageProcessingEnabled()
249257
public function testPsr3MessageProcessingDisabledOnNullHandler()
250258
{
251259
if (\Monolog\Logger::API < 2) {
252-
$this->markTestSkipped('This test requires Monolog v2');
260+
$this->markTestSkipped('This test requires Monolog v2 or above');
253261
}
254262
$container = $this->getContainer('process_psr_3_messages_null');
255263

@@ -263,7 +271,7 @@ public function testPsr3MessageProcessingDisabledOnNullHandler()
263271
public function testHandlersV2()
264272
{
265273
if (\Monolog\Logger::API < 2) {
266-
$this->markTestSkipped('This test requires Monolog v2');
274+
$this->markTestSkipped('This test requires Monolog v2 or above');
267275
}
268276
$this->getContainer('handlers');
269277

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ public function testSocketHandler()
297297

298298
public function testRavenHandlerWhenConfigurationIsWrong()
299299
{
300-
if (Logger::API === 2) {
301-
$this->markTestSkipped('Not valid for V2');
300+
if (Logger::API !== 1) {
301+
$this->markTestSkipped('Only valid on Monolog V1');
302302

303303
return;
304304
}
@@ -313,8 +313,8 @@ public function testRavenHandlerWhenConfigurationIsWrong()
313313

314314
public function testRavenHandlerWhenADSNIsSpecified()
315315
{
316-
if (Logger::API === 2) {
317-
$this->markTestSkipped('Not valid for V2');
316+
if (Logger::API !== 1) {
317+
$this->markTestSkipped('Only valid on Monolog V1');
318318

319319
return;
320320
}
@@ -339,8 +339,8 @@ public function testRavenHandlerWhenADSNIsSpecified()
339339

340340
public function testRavenHandlerWhenADSNAndAClientAreSpecified()
341341
{
342-
if (Logger::API === 2) {
343-
$this->markTestSkipped('Not valid for V2');
342+
if (Logger::API !== 1) {
343+
$this->markTestSkipped('Only valid on Monolog V1');
344344

345345
return;
346346
}
@@ -359,8 +359,8 @@ public function testRavenHandlerWhenADSNAndAClientAreSpecified()
359359

360360
public function testRavenHandlerWhenAClientIsSpecified()
361361
{
362-
if (Logger::API === 2) {
363-
$this->markTestSkipped('Not valid for V2');
362+
if (Logger::API !== 1) {
363+
$this->markTestSkipped('Only valid on Monolog V1');
364364

365365
return;
366366
}
@@ -692,8 +692,8 @@ public function v2RemovedDataProvider()
692692
*/
693693
public function testV2AddedOnV1($handlerType)
694694
{
695-
if (Logger::API === 2) {
696-
$this->markTestSkipped('Not valid for V2');
695+
if (Logger::API !== 1) {
696+
$this->markTestSkipped('Only valid on Monolog V1');
697697

698698
return;
699699
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
2222
"symfony/config": "~4.4 || ^5.0 || ^6.0",
2323
"symfony/http-kernel": "~4.4 || ^5.0 || ^6.0",
24-
"monolog/monolog": "~1.22 || ~2.0"
24+
"monolog/monolog": "^1.22 || ^2.0 || ^3.0"
2525
},
2626
"require-dev": {
2727
"symfony/yaml": "~4.4 || ^5.0 || ^6.0",

0 commit comments

Comments
 (0)