addition: Saloon testing utils without global state - #33
Merged
remipelhate merged 16 commits intoSep 8, 2026
Merged
Conversation
This is meant to replace the FakeResponse dataprovider which relies on global state.
This is not available in PhpUnit 11.5
remipelhate
deleted the
addition/saloon-testing-utils-without-global-state
branch
September 8, 2026 13:55
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.
Before moving towards hexagonal architecture, we developed some extensions on Saloon's testing utils. While those utils are mice to work with, they do come with the downside of relying on global state, often not allowing us to write pur unit tests for any implementation that sends Saloon requests.
This PR proposes a set of custom testing utils that don't build upon Saloon's native solution, but are more in line with our current standards.
With the new testing utils, this excerpt from the source code:
... can be rewritten to:
The only change required on implementation side is to typehint
Saloon\Http\Connectorinstead ofCoreBackendConnectordirectly. This does mean that the implementation has to be bound to the container explicitly.Deprecated
Craftzing\TestBench\Saloon\Doubles\FakeConnectorhas been deprecated in favour ofCraftzing\TestBench\Saloon\Doubles\FakeResponseConnector.Craftzing\TestBench\Saloon\DataProviders\FakeResponsehas been deprecated in favour or a more genericCraftzing\TestBench\PHPUnit\DataProviders\HttpStatusCodedata provider.Craftzing\TestBench\Saloon\Constraints\WasSenthas been deprecated in favour ofCraftzing\TestBench\Saloon\Doubles\FakeResponseConnector.Added
Craftzing\TestBench\Saloon\Doubles\FakeResponseConnectorcompletely bypasses Saloon's nativeMockClientimplementation and solely relies onCraftzing\TestBench\Saloon\Doubles\FakeResponseinstances.Craftzing\TestBench\Saloon\Doubles\SpyConnectoris a new Connector test double that can be used to spy on thesendmethod. It can be used as a decorator or standalone implementation and is mostly useful to make assertions that thesendmethod was never called.Craftzing\TestBench\PHPUnit\Constraint\PublicPropertiesComparatorhas been added as an alternative to PhpUnit's default ObjectComparator, which compares all properties regardless of their visibility or whether they're virtual.PublicPropertiesComparatorin contrary can be registered to only check the public properties of an object. E.g.: