Skip to content

Commit 310237c

Browse files
committed
Add test for Streaming implementation
1 parent 5a4d292 commit 310237c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/php/xp/lambda/LocalRuntime.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace xp\lambda;
22

33
use com\amazon\aws\lambda\{InvokeMode, Stream, RuntimeApi};
4+
use io\Channel;
45

56
class LocalRuntime extends RuntimeApi {
67
public $out;

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

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

3-
use com\amazon\aws\lambda\{Context, RuntimeApi, Lambda, Streaming};
3+
use com\amazon\aws\lambda\{Context, RuntimeApi, Lambda, Stream, Streaming};
44
use lang\IllegalArgumentException;
55
use test\{Assert, Expect, Test};
66

@@ -50,6 +50,24 @@ public function process($event, $context) { return 'Test'; }
5050
Assert::equals('Test', ($invokeable->callable)(null, new Context($this->headers, [])));
5151
}
5252

53+
#[Test]
54+
public function return_streaming() {
55+
$runtime= new RuntimeApi('localhost:9000');
56+
$invokeable= $runtime->invokeable(new class() implements Streaming {
57+
public function handle($event, $stream, $context) { $stream->write('Test'); }
58+
});
59+
$stream= new class() implements Stream {
60+
public $written= '';
61+
public function transmit($source, $mime= null) { /* NOOP */ }
62+
public function use($mime) { /** NOOP */ }
63+
public function write($bytes) { $this->written.= $bytes; }
64+
public function end() { /** NOOP */ }
65+
};
66+
($invokeable->callable)(null, $stream, new Context($this->headers, []));
67+
68+
Assert::equals('Test', $stream->written);
69+
}
70+
5371
#[Test, Expect(IllegalArgumentException::class)]
5472
public function cannot_return_null() {
5573
$runtime= new RuntimeApi('localhost:9000');

0 commit comments

Comments
 (0)