Skip to content

Commit 3916ec1

Browse files
committed
Fix tests and update swift_handler to be removed on Monolog 3
1 parent 3a3931a commit 3916ec1

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,22 +1002,36 @@ private function getHandlerClassByType($handlerType)
10021002
'slackbot',
10031003
];
10041004

1005-
if (Logger::API === 2) {
1005+
$v3HandlerTypesRemoved = [
1006+
'swift_mailer',
1007+
];
1008+
1009+
if (Logger::API >= 2) {
10061010
$typeToClassMapping = array_merge($typeToClassMapping, $v2HandlerTypesAdded);
10071011
foreach($v2HandlerTypesRemoved as $v2HandlerTypeRemoved) {
10081012
unset($typeToClassMapping[$v2HandlerTypeRemoved]);
10091013
}
10101014
}
10111015

1016+
if (Logger::API >= 3) {
1017+
foreach($v3HandlerTypesRemoved as $v3HandlerTypeRemoved) {
1018+
unset($typeToClassMapping[$v3HandlerTypeRemoved]);
1019+
}
1020+
}
1021+
10121022
if (!isset($typeToClassMapping[$handlerType])) {
10131023
if (Logger::API === 1 && array_key_exists($handlerType, $v2HandlerTypesAdded)) {
10141024
throw new \InvalidArgumentException(sprintf('"%s" was added in Monolog v2, please upgrade if you wish to use it.', $handlerType));
10151025
}
10161026

1017-
if (Logger::API === 2 && array_key_exists($handlerType, $v2HandlerTypesRemoved)) {
1027+
if (Logger::API >= 2 && array_key_exists($handlerType, $v2HandlerTypesRemoved)) {
10181028
throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v2.', $handlerType));
10191029
}
10201030

1031+
if (Logger::API >= 3 && array_key_exists($handlerType, $v3HandlerTypesRemoved)) {
1032+
throw new \InvalidArgumentException(sprintf('"%s" was removed in Monolog v3.', $handlerType));
1033+
}
1034+
10211035
throw new \InvalidArgumentException(sprintf('There is no handler class defined for handler "%s".', $handlerType));
10221036
}
10231037

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 0 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' => [

Tests/DependencyInjection/FixtureMonologExtensionTest.php

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

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

188192
$this->assertEquals([
@@ -211,6 +215,10 @@ public function testServerLog()
211215

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

216224
$this->assertEquals([
@@ -248,7 +256,7 @@ public function testPsr3MessageProcessingEnabled()
248256
public function testPsr3MessageProcessingDisabledOnNullHandler()
249257
{
250258
if (\Monolog\Logger::API < 2) {
251-
$this->markTestSkipped('This test requires Monolog v2');
259+
$this->markTestSkipped('This test requires Monolog v2 or above');
252260
}
253261
$container = $this->getContainer('process_psr_3_messages_null');
254262

@@ -262,7 +270,7 @@ public function testPsr3MessageProcessingDisabledOnNullHandler()
262270
public function testHandlersV2()
263271
{
264272
if (\Monolog\Logger::API < 2) {
265-
$this->markTestSkipped('This test requires Monolog v2');
273+
$this->markTestSkipped('This test requires Monolog v2 or above');
266274
}
267275
$this->getContainer('handlers');
268276

Tests/DependencyInjection/MonologExtensionTest.php

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

295295
public function testRavenHandlerWhenConfigurationIsWrong()
296296
{
297-
if (Logger::API === 2) {
298-
$this->markTestSkipped('Not valid for V2');
297+
if (Logger::API !== 1) {
298+
$this->markTestSkipped('Only valid on Monolog V1');
299299

300300
return;
301301
}
@@ -310,8 +310,8 @@ public function testRavenHandlerWhenConfigurationIsWrong()
310310

311311
public function testRavenHandlerWhenADSNIsSpecified()
312312
{
313-
if (Logger::API === 2) {
314-
$this->markTestSkipped('Not valid for V2');
313+
if (Logger::API !== 1) {
314+
$this->markTestSkipped('Only valid on Monolog V1');
315315

316316
return;
317317
}
@@ -336,8 +336,8 @@ public function testRavenHandlerWhenADSNIsSpecified()
336336

337337
public function testRavenHandlerWhenADSNAndAClientAreSpecified()
338338
{
339-
if (Logger::API === 2) {
340-
$this->markTestSkipped('Not valid for V2');
339+
if (Logger::API !== 1) {
340+
$this->markTestSkipped('Only valid on Monolog V1');
341341

342342
return;
343343
}
@@ -356,8 +356,8 @@ public function testRavenHandlerWhenADSNAndAClientAreSpecified()
356356

357357
public function testRavenHandlerWhenAClientIsSpecified()
358358
{
359-
if (Logger::API === 2) {
360-
$this->markTestSkipped('Not valid for V2');
359+
if (Logger::API !== 1) {
360+
$this->markTestSkipped('Only valid on Monolog V1');
361361

362362
return;
363363
}
@@ -689,8 +689,8 @@ public function v2RemovedDataProvider()
689689
*/
690690
public function testV2AddedOnV1($handlerType)
691691
{
692-
if (Logger::API === 2) {
693-
$this->markTestSkipped('Not valid for V2');
692+
if (Logger::API !== 1) {
693+
$this->markTestSkipped('Only valid on Monolog V1');
694694

695695
return;
696696
}

0 commit comments

Comments
 (0)