1818use Ymir \Runtime \Lambda \Response \ProcessResponse ;
1919use Ymir \Runtime \Tests \Mock \ConsoleCommandEventMockTrait ;
2020use Ymir \Runtime \Tests \Mock \InvocationEventInterfaceMockTrait ;
21+ use Ymir \Runtime \Tests \Mock \LoggerMockTrait ;
2122
2223/**
2324 * @covers \Ymir\Runtime\Lambda\Handler\ConsoleCommandLambdaEventHandler
@@ -26,31 +27,31 @@ class ConsoleCommandLambdaEventHandlerTest extends TestCase
2627{
2728 use ConsoleCommandEventMockTrait;
2829 use InvocationEventInterfaceMockTrait;
30+ use LoggerMockTrait;
2931
3032 public function testCanHandlePingEventType ()
3133 {
32- $ handler = new ConsoleCommandLambdaEventHandler ();
33-
34- $ this ->assertTrue ($ handler ->canHandle ($ this ->getConsoleCommandEventMock ()));
34+ $ this ->assertTrue ((new ConsoleCommandLambdaEventHandler ($ this ->getLoggerMock ()))->canHandle ($ this ->getConsoleCommandEventMock ()));
3535 }
3636
3737 public function testCanHandleWrongEventType ()
3838 {
39- $ handler = new ConsoleCommandLambdaEventHandler ();
40-
41- $ this ->assertFalse ($ handler ->canHandle ($ this ->getInvocationEventInterfaceMock ()));
39+ $ this ->assertFalse ((new ConsoleCommandLambdaEventHandler ($ this ->getLoggerMock ()))->canHandle ($ this ->getInvocationEventInterfaceMock ()));
4240 }
4341
4442 public function testHandleWithSuccessfulCommand ()
4543 {
4644 $ event = $ this ->getConsoleCommandEventMock ();
47- $ handler = new ConsoleCommandLambdaEventHandler ();
45+ $ logger = $ this -> getLoggerMock ();
4846
4947 $ event ->expects ($ this ->once ())
5048 ->method ('getCommand ' )
5149 ->willReturn ('ls -la ' );
5250
53- $ response = $ handler ->handle ($ event );
51+ $ logger ->expects ($ this ->once ())
52+ ->method ('info ' );
53+
54+ $ response = (new ConsoleCommandLambdaEventHandler ($ logger ))->handle ($ event );
5455 $ responseData = $ response ->getResponseData ();
5556
5657 $ this ->assertInstanceOf (ProcessResponse::class, $ response );
@@ -61,13 +62,16 @@ public function testHandleWithSuccessfulCommand()
6162 public function testHandleWithUnsuccessfulCommand ()
6263 {
6364 $ event = $ this ->getConsoleCommandEventMock ();
64- $ handler = new ConsoleCommandLambdaEventHandler ();
65+ $ logger = $ this -> getLoggerMock ();
6566
6667 $ event ->expects ($ this ->once ())
6768 ->method ('getCommand ' )
6869 ->willReturn ('foo ' );
6970
70- $ response = $ handler ->handle ($ event );
71+ $ logger ->expects ($ this ->once ())
72+ ->method ('info ' );
73+
74+ $ response = (new ConsoleCommandLambdaEventHandler ($ logger ))->handle ($ event );
7175 $ responseData = $ response ->getResponseData ();
7276
7377 $ this ->assertInstanceOf (ProcessResponse::class, $ response );
@@ -80,8 +84,6 @@ public function testHandleWithWrongEventType()
8084 $ this ->expectException (\InvalidArgumentException::class);
8185 $ this ->expectExceptionMessage ('ConsoleCommandLambdaEventHandler can only handle ConsoleCommandEvent objects ' );
8286
83- $ handler = new ConsoleCommandLambdaEventHandler ();
84-
85- $ handler ->handle ($ this ->getInvocationEventInterfaceMock ());
87+ (new ConsoleCommandLambdaEventHandler ($ this ->getLoggerMock ()))->handle ($ this ->getInvocationEventInterfaceMock ());
8688 }
8789}
0 commit comments