Verified Commit a3448448 authored by Dave Long's avatar Dave Long
Browse files

fix: #3622446 DrupalConsoleLogger throws incorrect exception

By: mfb
By: dcam
By: oily
(cherry picked from commit 55148447)
parent de51a841
Loading
Loading
Loading
Loading
Loading
+2 −1
Changes for core/lib/Drupal/Core/Command/DrupalConsoleLogger.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Logger\RfcLogLevel;
use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LogLevel;
@@ -54,7 +55,7 @@ public static function toPsr3(int $level): string {
      RfcLogLevel::NOTICE => LogLevel::NOTICE,
      RfcLogLevel::INFO => LogLevel::INFO,
      RfcLogLevel::DEBUG => LogLevel::DEBUG,
      default => throw new \InvalidArgumentException("Invalid log level: $level"),
      default => throw new InvalidArgumentException("Invalid log level: $level"),
    };
  }

+29 −0
Changes for core/tests/Drupal/Tests/Core/Command/DrupalConsoleLoggerTest.php: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\Core\Command;

use Drupal\Core\Command\DrupalConsoleLogger;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use Psr\Log\InvalidArgumentException;

/**
 * Tests DrupalConsoleLogger.
 */
#[Group('command')]
#[CoversClass(DrupalConsoleLogger::class)]
class DrupalConsoleLoggerTest extends UnitTestCase {

  /**
   * Tests the exception thrown by ::toPsr3() due to an invalid argument.
   */
  public function testToPsr3Exception(): void {
    $this->expectException(InvalidArgumentException::class);
    $this->expectExceptionMessageIs('Invalid log level: -1000');
    DrupalConsoleLogger::toPsr3(-1000);
  }

}