Skip to content

Commit 17cd362

Browse files
committed
Also test Lambda implementations
1 parent 26e9848 commit 17cd362

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/test/php/com/amazon/aws/lambda/unittest/BufferedTest.class.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php namespace com\amazon\aws\lambda\unittest;
22

3-
use com\amazon\aws\lambda\Context;
3+
use com\amazon\aws\lambda\{Context, Lambda};
44
use lang\IllegalStateException;
5-
use test\{Assert, Test};
5+
use test\{Assert, Test, Values};
66

77
class BufferedTest extends RuntimeTest {
88
use TestContext;
99

1010
/**
1111
* Invokes a lambda and returns the response
1212
*
13-
* @param function(var, com.amazon.aws.lambda.Context, com.amazon.aws.lambda.Stream): void
13+
* @param function(var, com.amazon.aws.lambda.Context): void
1414
* @return string
1515
*/
1616
private function invoke($lambda) {
@@ -21,16 +21,30 @@ private function invoke($lambda) {
2121
;
2222
}
2323

24+
/**
25+
* Lambda implementations for `response` test.
26+
*
27+
* @return iterable
28+
*/
29+
private function implementations() {
30+
yield [function($event, $context) {
31+
return ['test' => true];
32+
}];
33+
yield [new class() implements Lambda {
34+
public function process($event, $context) {
35+
return ['test' => true];
36+
}
37+
}];
38+
}
39+
2440
#[Test]
2541
public function can_create() {
2642
$this->runtime->buffered();
2743
}
2844

29-
#[Test]
30-
public function response() {
31-
$response= $this->invoke(function($event, $context) {
32-
return ['test' => true];
33-
});
45+
#[Test, Values(from: 'implementations')]
46+
public function response($lambda) {
47+
$response= $this->invoke($this->runtime->invokeable($lambda)->callable);
3448

3549
Assert::equals(
3650
"POST /2018-06-01/runtime/invocation/3e1afeb0-cde4-1d0e-c3c0-66b15046bb88/response HTTP/1.1\r\n".

src/test/php/com/amazon/aws/lambda/unittest/StreamingTest.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ private function invoke($lambda) {
2828
* @return iterable
2929
*/
3030
private function implementations() {
31-
yield [$this->runtime->invokeable(function($event, $stream, $context) {
31+
yield [function($event, $stream, $context) {
3232
$stream->use('text/event-stream');
3333
$stream->write("data: One\n\n");
3434
$stream->write("data: Two\n\n");
35-
})];
36-
yield [$this->runtime->invokeable(new class() implements Streaming {
35+
}];
36+
yield [new class() implements Streaming {
3737
public function handle($event, $stream, $context) {
3838
$stream->use('text/event-stream');
3939
$stream->write("data: One\n\n");
4040
$stream->write("data: Two\n\n");
4141
}
42-
})];
42+
}];
4343
}
4444

4545
#[Test]
@@ -84,7 +84,7 @@ public function reports_exceptions_before_streaming_via_error() {
8484

8585
#[Test, Values(from: 'implementations')]
8686
public function write_event_stream($lambda) {
87-
$response= $this->invoke($lambda->callable);
87+
$response= $this->invoke($this->runtime->invokeable($lambda)->callable);
8888

8989
Assert::equals(
9090
"POST /2018-06-01/runtime/invocation/3e1afeb0-cde4-1d0e-c3c0-66b15046bb88/response HTTP/1.1\r\n".

0 commit comments

Comments
 (0)