[Platform] Add Mock test provider for routing-aware, any-result-type mocks#2123
Merged
chr-hertel merged 1 commit intoJun 21, 2026
Merged
Conversation
This was referenced May 30, 2026
Contributor
|
Shall we name it to Mock? AFAIK this is more the Symfony naming |
b44dd7c to
42fc0c5
Compare
Contributor
Author
chr-hertel
reviewed
Jun 19, 2026
chr-hertel
reviewed
Jun 19, 2026
chr-hertel
reviewed
Jun 19, 2026
chr-hertel
reviewed
Jun 19, 2026
chr-hertel
reviewed
Jun 19, 2026
Contributor
Author
|
@chr-hertel fixed :) |
a7158db to
46bd698
Compare
Member
|
The last thing i'm thinking about is merging the namespaces by basically moving this to the |
Contributor
Author
doing it at the moment :) |
Contributor
Author
|
@chr-hertel done |
d669751 to
90cc232
Compare
90cc232 to
2e301e8
Compare
Member
|
Thank you @wachterjohannes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a provider-level test mock under
Symfony\AI\Platform\Mockthat registers like a real bridge, participates in model routing, returns scripted responses of any result type, and records call history for assertions.Why not just
Test\InMemoryPlatform?Test\InMemoryPlatformis a platform-level fake: it replaces the wholePlatform, ignores routing, has no model catalog, and returns text only — perfect for unit tests injecting aPlatformInterfacedirectly. The newMockprovider is provider-level and complementary. Reach for it when a test must:ObjectResult,StreamResult,ToolCallResult,VectorResult),getCalls()).Design
MockModelClient::request()resolves a scriptedResultInterface(or wraps a string inTextResult), records the call, and threads the result through theobjectslot of the existingInMemoryRawResult.MockResultConverter::convert()pulls it back out and returns it verbatim — so every result type is supported with no per-type conversion code. The embedding-mock case falls out for free by scripting aVectorResult.Usage
It lives in platform core (not under
src/Bridge/, whichsplitsh.jsonexcludes from thesymfony/ai-platformpackage), so it ships with the platform exactly likeTest\InMemoryPlatform.Scope / follow-ups
ai-bundleconfig node (framework.ai.platform.mock) — closures cannot be expressed in YAML; most consumers register the mock in a test kernel / compiler pass. The PHP API is what unblocks them.Contract/normalizer (the mock records payloads raw) and fault injection (scripted exceptions) — easy to add later.Verification
vendor/bin/phpunit tests/Mock— 21 tests, 38 assertions, green.vendor/bin/phpstan analyse— clean.php-cs-fixer— clean.