diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index a34075793..897d9853f 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -40,12 +40,12 @@ public function onConsoleError(ConsoleErrorEvent $event) $error = $event->getError(); if (!$inputString = $this->getInputString($event)) { - $this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); + $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); return; } - $this->logger->error('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); + $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); } public function onConsoleTerminate(ConsoleTerminateEvent $event) diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index ce3df1a0e..2bafab040 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -30,35 +30,35 @@ public function testOnConsoleError() { $error = new \TypeError('An error occurred'); - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) - ->method('error') + ->method('critical') ->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred']) ; $listener = new ErrorListener($logger); - $listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->getOutput(), $error, new Command('test:run'))); + $listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->createMock(OutputInterface::class), $error, new Command('test:run'))); } public function testOnConsoleErrorWithNoCommandAndNoInputString() { $error = new \RuntimeException('An error occurred'); - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) - ->method('error') + ->method('critical') ->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred']) ; $listener = new ErrorListener($logger); - $listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->getOutput(), $error)); + $listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->createMock(OutputInterface::class), $error)); } public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('debug') @@ -71,7 +71,7 @@ public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog() public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->never()) ->method('debug') @@ -83,7 +83,7 @@ public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog() public function testGetSubscribedEvents() { - $this->assertEquals( + $this->assertSame( [ 'console.error' => ['onConsoleError', -128], 'console.terminate' => ['onConsoleTerminate', -128], @@ -94,7 +94,7 @@ public function testGetSubscribedEvents() public function testAllKindsOfInputCanBeLogged() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->exactly(3)) ->method('debug') @@ -109,7 +109,7 @@ public function testAllKindsOfInputCanBeLogged() public function testCommandNameIsDisplayedForNonStringableInput() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('debug') @@ -120,19 +120,9 @@ public function testCommandNameIsDisplayedForNonStringableInput() $listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255)); } - private function getLogger() - { - return $this->getMockForAbstractClass(LoggerInterface::class); - } - private function getConsoleTerminateEvent(InputInterface $input, $exitCode) { - return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->getOutput(), $exitCode); - } - - private function getOutput() - { - return $this->createMock(OutputInterface::class); + return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->createMock(OutputInterface::class), $exitCode); } }