Skip to content

Commit 26e9848

Browse files
committed
Add tests for streaming (3-arg) functions
1 parent f89de92 commit 26e9848

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function endpoint_timeout_is_15_minutes() {
3535
}
3636

3737
#[Test]
38-
public function return_function() {
38+
public function return_lambda_function() {
3939
$invokeable= (new RuntimeApi('localhost:9000'))->invokeable(function($event, $context) {
4040
return 'Test';
4141
});
@@ -52,19 +52,24 @@ public function process($event, $context) { return 'Test'; }
5252
Assert::equals('Test', ($invokeable->callable)(null, new Context($this->headers, [])));
5353
}
5454

55+
#[Test]
56+
public function return_streaming_function() {
57+
$invokeable= (new RuntimeApi('localhost:9000'))->invokeable(function($event, $stream, $context) {
58+
$stream->write('Test');
59+
});
60+
61+
$stream= new TestStream();
62+
($invokeable->callable)(null, $stream, new Context($this->headers, []));
63+
Assert::equals('Test', $stream->written);
64+
}
65+
5566
#[Test]
5667
public function return_streaming() {
5768
$invokeable= (new RuntimeApi('localhost:9000'))->invokeable(new class() implements Streaming {
5869
public function handle($event, $stream, $context) { $stream->write('Test'); }
5970
});
60-
$stream= new class() implements Stream {
61-
public $written= '';
62-
public function transmit($source, $mime= null) { /* NOOP */ }
63-
public function use($mime) { /** NOOP */ }
64-
public function write($bytes) { $this->written.= $bytes; }
65-
public function end() { /** NOOP */ }
66-
};
6771

72+
$stream= new TestStream();
6873
($invokeable->callable)(null, $stream, new Context($this->headers, []));
6974
Assert::equals('Test', $stream->written);
7075
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php namespace com\amazon\aws\lambda\unittest;
2+
3+
use com\amazon\aws\lambda\Stream;
4+
5+
class TestStream implements Stream {
6+
public $written= '';
7+
8+
public function transmit($source, $mime= null) { /* NOOP */ }
9+
10+
public function use($mime) { /** NOOP */ }
11+
12+
public function write($bytes) { $this->written.= $bytes; }
13+
14+
public function end() { /** NOOP */ }
15+
}

0 commit comments

Comments
 (0)