Skip to content

Commit a5e89d5

Browse files
OskarStarkchalasr
authored andcommitted
Use createMock() instead of a getter
1 parent 24026c4 commit a5e89d5

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

Tests/EventListener/ErrorListenerTest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,35 @@ public function testOnConsoleError()
3030
{
3131
$error = new \TypeError('An error occurred');
3232

33-
$logger = $this->getLogger();
33+
$logger = $this->createMock(LoggerInterface::class);
3434
$logger
3535
->expects($this->once())
3636
->method('error')
3737
->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'])
3838
;
3939

4040
$listener = new ErrorListener($logger);
41-
$listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->getOutput(), $error, new Command('test:run')));
41+
$listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->createMock(OutputInterface::class), $error, new Command('test:run')));
4242
}
4343

4444
public function testOnConsoleErrorWithNoCommandAndNoInputString()
4545
{
4646
$error = new \RuntimeException('An error occurred');
4747

48-
$logger = $this->getLogger();
48+
$logger = $this->createMock(LoggerInterface::class);
4949
$logger
5050
->expects($this->once())
5151
->method('error')
5252
->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred'])
5353
;
5454

5555
$listener = new ErrorListener($logger);
56-
$listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->getOutput(), $error));
56+
$listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->createMock(OutputInterface::class), $error));
5757
}
5858

5959
public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
6060
{
61-
$logger = $this->getLogger();
61+
$logger = $this->createMock(LoggerInterface::class);
6262
$logger
6363
->expects($this->once())
6464
->method('debug')
@@ -71,7 +71,7 @@ public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
7171

7272
public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
7373
{
74-
$logger = $this->getLogger();
74+
$logger = $this->createMock(LoggerInterface::class);
7575
$logger
7676
->expects($this->never())
7777
->method('debug')
@@ -83,7 +83,7 @@ public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
8383

8484
public function testGetSubscribedEvents()
8585
{
86-
$this->assertEquals(
86+
$this->assertSame(
8787
[
8888
'console.error' => ['onConsoleError', -128],
8989
'console.terminate' => ['onConsoleTerminate', -128],
@@ -94,7 +94,7 @@ public function testGetSubscribedEvents()
9494

9595
public function testAllKindsOfInputCanBeLogged()
9696
{
97-
$logger = $this->getLogger();
97+
$logger = $this->createMock(LoggerInterface::class);
9898
$logger
9999
->expects($this->exactly(3))
100100
->method('debug')
@@ -109,7 +109,7 @@ public function testAllKindsOfInputCanBeLogged()
109109

110110
public function testCommandNameIsDisplayedForNonStringableInput()
111111
{
112-
$logger = $this->getLogger();
112+
$logger = $this->createMock(LoggerInterface::class);
113113
$logger
114114
->expects($this->once())
115115
->method('debug')
@@ -120,19 +120,9 @@ public function testCommandNameIsDisplayedForNonStringableInput()
120120
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
121121
}
122122

123-
private function getLogger()
124-
{
125-
return $this->getMockForAbstractClass(LoggerInterface::class);
126-
}
127-
128123
private function getConsoleTerminateEvent(InputInterface $input, $exitCode)
129124
{
130-
return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->getOutput(), $exitCode);
131-
}
132-
133-
private function getOutput()
134-
{
135-
return $this->createMock(OutputInterface::class);
125+
return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->createMock(OutputInterface::class), $exitCode);
136126
}
137127
}
138128

0 commit comments

Comments
 (0)