2020use Ymir \Runtime \Tests \Mock \FunctionMockTrait ;
2121use Ymir \Runtime \Tests \Mock \InvocationEventInterfaceMockTrait ;
2222use Ymir \Runtime \Tests \Mock \LambdaClientMockTrait ;
23+ use Ymir \Runtime \Tests \Mock \LoggerMockTrait ;
2324use Ymir \Runtime \Tests \Mock \WarmUpEventMockTrait ;
2425
2526class WarmUpEventHandlerTest extends TestCase
2627{
2728 use FunctionMockTrait;
2829 use InvocationEventInterfaceMockTrait;
2930 use LambdaClientMockTrait;
31+ use LoggerMockTrait;
3032 use WarmUpEventMockTrait;
3133
3234 public function testCanHandleWarmUpEventType (): void
3335 {
34- $ this ->assertTrue ((new WarmUpEventHandler ($ this ->getLambdaClientMock ()))->canHandle ($ this ->getWarmUpEventMock ()));
36+ $ this ->assertTrue ((new WarmUpEventHandler ($ this ->getLambdaClientMock (), $ this -> getLoggerMock () ))->canHandle ($ this ->getWarmUpEventMock ()));
3537 }
3638
3739 public function testCanHandleWrongEventType (): void
3840 {
39- $ this ->assertFalse ((new WarmUpEventHandler ($ this ->getLambdaClientMock ()))->canHandle ($ this ->getInvocationEventInterfaceMock ()));
41+ $ this ->assertFalse ((new WarmUpEventHandler ($ this ->getLambdaClientMock (), $ this -> getLoggerMock () ))->canHandle ($ this ->getInvocationEventInterfaceMock ()));
4042 }
4143
4244 public function testHandleDoesntInvokeAdditionalFunctionsWhenConcurrencyIsOne (): void
@@ -51,7 +53,7 @@ public function testHandleDoesntInvokeAdditionalFunctionsWhenConcurrencyIsOne():
5153 $ lambdaClient ->expects ($ this ->never ())
5254 ->method ('invoke ' );
5355
54- $ reponse = (new WarmUpEventHandler ($ lambdaClient ))->handle ($ event );
56+ $ reponse = (new WarmUpEventHandler ($ lambdaClient, $ this -> getLoggerMock () ))->handle ($ event );
5557
5658 $ this ->assertInstanceOf (HttpResponse::class, $ reponse );
5759 $ this ->assertSame ([
@@ -69,11 +71,16 @@ public function testHandleInvokesAdditionalFunctions(): void
6971 $ event = $ this ->getWarmUpEventMock ();
7072 $ getenv = $ this ->getFunctionMock ($ this ->getNamespace (WarmUpEventHandler::class), 'getenv ' );
7173 $ lambdaClient = $ this ->getLambdaClientMock ();
74+ $ logger = $ this ->getLoggerMock ();
7275
7376 $ event ->expects ($ this ->any ())
7477 ->method ('getConcurrency ' )
7578 ->willReturn (3 );
7679
80+ $ logger ->expects ($ this ->once ())
81+ ->method ('debug ' )
82+ ->with ($ this ->identicalTo ('Warming up 3 additional functions ' ));
83+
7784 $ getenv ->expects ($ this ->once ())
7885 ->with ($ this ->identicalTo ('AWS_LAMBDA_FUNCTION_NAME ' ))
7986 ->willReturn ('function-name ' );
@@ -85,10 +92,10 @@ public function testHandleInvokesAdditionalFunctions(): void
8592 'Qualifier ' => 'deployed ' ,
8693 'InvocationType ' => 'Event ' ,
8794 'LogType ' => 'None ' ,
88- 'Payload ' => '{"ping": true} ' ,
89- ]);
95+ 'Payload ' => '{"ping": true} ' ,
96+ ]);
9097
91- $ reponse = (new WarmUpEventHandler ($ lambdaClient ))->handle ($ event );
98+ $ reponse = (new WarmUpEventHandler ($ lambdaClient, $ logger ))->handle ($ event );
9299
93100 $ this ->assertInstanceOf (HttpResponse::class, $ reponse );
94101 $ this ->assertSame ([
@@ -112,14 +119,14 @@ public function testHandleWithNoEnvironmentVariable(): void
112119 ->method ('getConcurrency ' )
113120 ->willReturn (3 );
114121
115- (new WarmUpEventHandler ($ this ->getLambdaClientMock ()))->handle ($ event );
122+ (new WarmUpEventHandler ($ this ->getLambdaClientMock (), $ this -> getLoggerMock () ))->handle ($ event );
116123 }
117124
118125 public function testHandleWithWrongEventType (): void
119126 {
120127 $ this ->expectException (\InvalidArgumentException::class);
121128 $ this ->expectExceptionMessage ('WarmUpEventHandler can only handle WarmUpEvent objects ' );
122129
123- (new WarmUpEventHandler ($ this ->getLambdaClientMock ()))->handle ($ this ->getInvocationEventInterfaceMock ());
130+ (new WarmUpEventHandler ($ this ->getLambdaClientMock (), $ this -> getLoggerMock () ))->handle ($ this ->getInvocationEventInterfaceMock ());
124131 }
125132}
0 commit comments