saloon icon indicating copy to clipboard operation
saloon copied to clipboard

Allow partial mocking

Open epixian opened this issue 10 months ago • 2 comments

When testing end to end I might be hitting my own API which in turn sends to another API via background job or something. I don't have access to the connector or request(s) in these instances, and sometimes I would like to be able to mock some requests but not others.

Would be nice to be able to fall back to sending an actual request if a mock response for a given endpoint isn't found. Since mock responses are injected via DetermineMockResponse (a RequestMiddleware), I think you could do this just by returning the $pendingRequest instead of throwing a NoMockResponseFoundException.

epixian avatar Jun 19 '25 20:06 epixian

Thanks for the idea @epixian I quite like the idea too - perhaps you could initiate it by using Saloon::fake()->partial() or new PartialMockClient perhaps?

Sammyjo20 avatar Jun 21 '25 10:06 Sammyjo20

I was thinking to just modify the existing MockClient with a chainable allowFallback(bool $allow = true) method (or similar) to toggle no mock response found handling. This would also give you the ability to turn it on and off as needed. What do you think?

epixian avatar Jun 23 '25 12:06 epixian