Repository navigation
Conversation
Marshalling a binary event without data read a missing array key. That raised an 'Undefined array key "data"' warning and wrote the text null as the body, even for non-JSON content types. The body is now empty. The unmarshaller reads an empty binary body as an event without data instead of failing with InvalidPayloadSyntaxException, so the SDK can read back what it sends. Signed-off-by: emir <52245396+EmiRZx@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change to handle events without data using empty binary bodies.
No open issues 🎉
What changed in this PR
Fixes #67 by using an empty binary body for events without data and accepting empty bodies when deserializing.
Changes:
- Avoids accessing a missing
datakey during serialization. - Interprets an empty binary body as no event data.
- Adds serializer, deserializer, and HTTP round-trip regression tests.
Older receivers must be upgraded before senders adopt the new wire format.
| File | Description |
|---|---|
| tests/Unit/Serializers/JsonSerializerTest.php | Tests empty-body serialization. |
| tests/Unit/Serializers/JsonDeserializerTest.php | Tests empty-body deserialization. |
| tests/Unit/Http/MarshallerTest.php | Tests an HTTP round trip without data. |
| src/Serializers/JsonSerializer.php | Emits an empty body when data is absent. |
| src/Serializers/JsonDeserializer.php | Accepts an empty body as no data. |
Review effort: Balanced
|
@EmiRZx for an existing app, this will switch from getting an error to return an empty body, right? |
|
mostly yes. on receiving changes too. an empty body used to throw |
That scares me a little. |
|
this stayed on my mind too and I looked into it a bit more. Go, JavaScript, Python, Java, Rust and C# all send an empty body for an event without data. so released sdk-php receivers already throw on events without data from any other SDK. most of them also leave out a safer way is two steps. this PR could keep sending |
fixes #67. a binary event without data now gets an empty body. an empty binary body unmarshals to an event without data, so the SDK reads back what it sends. new tests cover the serializer, the deserializer and an HTTP round trip. they fail on
mainand pass here. tests pass on PHP 7.4 and 8.4. phpcs and psalm are clean.note that the body on the wire changes from
nullto empty. receivers on 1.2.0 and older reject an empty body. they should be upgraded before senders.