1+ <?php namespace com \amazon \aws \lambda \unittest ;
2+
3+ use com \amazon \aws \lambda \Handler ;
4+ use io \streams \{StringWriter , MemoryOutputStream };
5+ use lang \{ClassLoader , IllegalArgumentException , ClassNotFoundException };
6+ use test \{Assert , Before , Expect , Test };
7+ use xp \lambda \AwsRunner ;
8+
9+ class AwsRunnerTest {
10+ private $ impl ;
11+
12+ #[Before]
13+ public function impl () {
14+ $ this ->impl = ClassLoader::defineClass ('AwsRunnerTest_Handler ' , Handler::class, [], [
15+ 'target ' => function () {
16+ return function ($ event , $ context ) { /* NOOP */ };
17+ }
18+ ]);
19+ $ this ->writer = new StringWriter (new MemoryOutputStream ());
20+ }
21+
22+ #[Test]
23+ public function handler_determined_from_environment () {
24+ $ handler = AwsRunner::handler (['_HANDLER ' => $ this ->impl ->getName ()], $ this ->writer );
25+ Assert::instance ($ this ->impl , $ handler );
26+ }
27+
28+ #[Test, Expect(class: IllegalArgumentException::class, message: 'Class util.Date is not a lambda handler ' )]
29+ public function handler_must_extend_base_class () {
30+ AwsRunner::handler (['_HANDLER ' => 'util.Date ' ], $ this ->writer );
31+ }
32+
33+ #[Test, Expect(class: ClassNotFoundException::class, message: 'Class "" could not be found ' )]
34+ public function without_handler () {
35+ AwsRunner::handler ([], $ this ->writer );
36+ }
37+
38+ #[Test]
39+ public function endpoint_url_determined_from_environment () {
40+ $ endpoint = AwsRunner::endpoint (['AWS_LAMBDA_RUNTIME_API ' => 'localhost:9000 ' ], 'invocation/next ' );
41+ Assert::equals (
42+ 'http://localhost:9000/2018-06-01/runtime/invocation/next ' ,
43+ $ endpoint ->getUrl ()->getCanonicalURL ()
44+ );
45+ }
46+
47+ #[Test]
48+ public function endpoint_timeout_is_15_minutes () {
49+ $ endpoint = AwsRunner::endpoint (['AWS_LAMBDA_RUNTIME_API ' => 'localhost:9000 ' ], 'invocation/next ' );
50+ Assert::equals (15 * 60 , $ endpoint ->getTimeout ());
51+ }
52+ }
0 commit comments