Skip to content

Introduce MessageEncoderInterface#308

Open
vjik wants to merge 20 commits into
masterfrom
serialize-wrapper
Open

Introduce MessageEncoderInterface#308
vjik wants to merge 20 commits into
masterfrom
serialize-wrapper

Conversation

@vjik

@vjik vjik commented Jun 11, 2026

Copy link
Copy Markdown
Member
Q A
Is bugfix?
New feature?
Breaks BC? ✔️
Tests pass? ✔️

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (22b1eac) to head (721d2ca).

Files with missing lines Patch % Lines
src/Message/Serializer/MessageSerializer.php 0.00% 28 Missing ⚠️
src/Message/Serializer/JsonMessageEncoder.php 0.00% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             master    #308   +/-   ##
========================================
  Coverage      0.00%   0.00%           
- Complexity      330     336    +6     
========================================
  Files            49      50    +1     
  Lines           909     920   +11     
========================================
- Misses          909     920   +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors message serialization by introducing a dedicated wire-format abstraction (MessageEncoderInterface) and replacing the previous JsonMessageSerializer / MessageSerializerInterface with a new MessageSerializer that delegates encoding/decoding to an encoder (default: JSON).

Changes:

  • Added MessageEncoderInterface + MessageEncoderException and implemented JsonMessageEncoder.
  • Added MessageSerializer to preserve/restore original message class via metadata while delegating wire encoding to the encoder.
  • Updated tests, benchmarks, DI config, and docs to the new serializer/encoder structure; removed legacy serializer types.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Message/Serializer/MessageEncoderInterface.php New abstraction for encoding/decoding message parts to/from strings.
src/Message/Serializer/MessageEncoderException.php New exception type for encoder failures.
src/Message/Serializer/JsonMessageEncoder.php JSON implementation of the new encoder interface.
src/Message/Serializer/MessageSerializer.php New serializer that uses an encoder and restores original message class from metadata.
src/Message/MessageSerializerInterface.php Removed legacy serializer interface (BC break).
src/Message/JsonMessageSerializer.php Removed legacy JSON serializer (replaced by MessageSerializer + JsonMessageEncoder).
config/di.php DI now binds MessageEncoderInterface to JsonMessageEncoder.
docs/guide/en/messages-and-handlers.md Docs updated to reference JsonMessageEncoder / MessageEncoderInterface.
docs/guide/en/consuming-messages-from-external-systems.md Docs updated to explain MessageSerializer + encoder responsibilities and JSON payload format.
docs/guide/en/best-practices.md Docs updated to reference JsonMessageEncoder as the default JSON mechanism.
tests/Unit/Message/Serializer/MessageSerializerTest.php New unit tests for MessageSerializer behavior (class restoration, envelopes, metadata).
tests/Unit/Message/Serializer/JsonMessageSerializerTest.php New unit tests for JSON decode validation (currently misnamed vs encoder).
tests/Unit/Message/JsonMessageSerializerTest.php Removed legacy serializer tests (replaced by new unit tests).
tests/Benchmark/Support/VoidAdapter.php Benchmark adapter updated to use the new MessageSerializer.
tests/Benchmark/QueueBench.php Benchmark updated for new serializer/encoder usage (currently contains a method call bug).
Comments suppressed due to low confidence (1)

tests/Benchmark/QueueBench.php:93

  • MessageSerializer doesn't have an encode() method (it exposes serialize()/unserialize()). These benchmark params will trigger a fatal error when the benchmark is executed.
        yield 'simple mapping' => ['message' => $this->serializer->serialize(new GenericMessage('foo', 'bar'))];
        yield 'with envelopes mapping' => [
            'message' => $this->serializer->serialize(
                new FailureEnvelope(

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Unit/Message/Serializer/JsonMessageSerializerTest.php Outdated
@vjik vjik requested a review from a team June 11, 2026 07:48
@vjik vjik added the status:code review The pull request needs review. label Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.

Comment thread tests/Unit/Message/Serializer/MessageSerializerTest.php Outdated
Comment thread docs/guide/en/messages-and-handlers.md Outdated
Comment thread src/Message/Serializer/MessageEncoderException.php Outdated
Comment thread src/Message/Serializer/MessageSerializer.php Outdated
Comment thread docs/guide/en/consuming-messages-from-external-systems.md
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
vjik and others added 5 commits June 12, 2026 13:10
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread tests/Benchmark/QueueBench.php
Comment thread tests/Benchmark/Support/VoidAdapter.php
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
Comment thread docs/guide/en/messages-and-handlers.md Outdated
Comment thread src/Message/Serializer/MessageEncoderInterface.php Outdated
Comment thread src/Message/Serializer/MessageSerializer.php
Comment thread src/Message/Serializer/MessageSerializer.php Outdated
Comment thread src/Message/Serializer/MessageSerializer.php Outdated
}

return $this->encoder->encode([
'type' => $message->getType(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type should be enough to get the message class from the mapping.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use one class with different types. For example:

$message1 = new GenericMessage(type: 'send-email', ...);
$message2 = new GenericMessage(type: 'process-order', ...);

@samdark samdark Jun 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is OK. Message payload will contain send-email, process-order and both will resolve to the same class via mapping (or to GenericMessage if either type is not there or there's no mapping for it).

@vjik vjik requested a review from samdark June 12, 2026 13:13
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
Comment thread docs/guide/en/consuming-messages-from-external-systems.md Outdated
vjik and others added 2 commits June 13, 2026 08:44
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
@vjik vjik requested a review from samdark June 13, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants