Skip to content

Commit 010835c

Browse files
authored
fix: allows json body with binary event (#63)
1 parent 86cdead commit 010835c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/CloudEventFunctionWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function getEventType(ServerRequestInterface $request)
107107

108108
private function fromBinaryRequest(
109109
ServerRequestInterface $request,
110-
string $data
110+
$data // mixed, can be "string" or "array"
111111
): CloudEvent {
112112
$content = [];
113113

tests/CloudEventFunctionsWrapperTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ public function testInvalidJsonBinaryCloudEventRequestBody()
9898
$this->assertEquals('crash', $response->getHeaderLine('X-Google-Status'));
9999
}
100100

101+
public function testValidJsonBinaryCloudEventRequestBody()
102+
{
103+
$request = new ServerRequest('POST', '/', [
104+
'ce-id' => 'fooBar',
105+
'ce-source' => 'my-source',
106+
'ce-specversion' => '1.0',
107+
'ce-type' => 'my.type',
108+
'Content-Type' => 'application/json',
109+
], '{"this":"isjson"}');
110+
$cloudEventFunctionWrapper = new CloudEventFunctionWrapper(
111+
[$this, 'invokeThisPartial']
112+
);
113+
$response = $cloudEventFunctionWrapper->execute($request);
114+
$this->assertEquals(200, $response->getStatusCode());
115+
}
116+
101117
public function testNoFunctionParameters()
102118
{
103119
$this->expectException('LogicException');

0 commit comments

Comments
 (0)