Replies: 1 comment 7 replies
-
Hey @derheyne Many thanks for your message - and I love hearing feedback about how Saloon is useful for projects like yours! Great find by the way, and I think your suggested idea of base64_encoding and decoding the body before serializing the recorded response/fixture would be a sensible option. I assume that would mean it doesn't matter if there are any weird UTF-8 characters, it would be stored in a nice, standardised way. I would be very willing to help out with this, do you have any suggestions on how I could replicate it? Does the API your returning just return the raw file contents as plain text or within JSON? I could quite easily build an endpoint in my Let me know your thoughts and how I can replicate it. I will likely fix both v1 and v2 as I understand people may still be on version one. |
Beta Was this translation helpful? Give feedback.
-
Hey Sam! Love your package! It really came in clutch for version 2 of our app and the upgrade to Saloon v2 is already underway.
A small thing we've found during testing APIs is the inability to save fixtures of requests returning files. Instead, it throws an error
Malformed UTF-8 characters, possibly incorrectly encoded
. This most likely happens because the string representation of the resource contains some weird, non-UTF8, characters.I got it working by encoding the request body with base64 when
mb_check_encoding
returnsfalse
:Unfortunately, it's quite complicated to change since
FixtureData
in v1 is deeply nested in some classes that can't easily be overwritten.MockResponse::fixture()
→Fixture::getMockResponse()
→FixtureData
SaloonRequest::getRequestManager()
→RequestManager::send()
→RequestManager::createGuzzleClient()
→FixtureRecorderMiddleware::storeResponse()
From what I've tried it's basically impossible to get the
FixtureRecorderMiddleware
overwritten becuase it's always pushed at the end of Guzzle's handler stack and overwriting the entire trace for reading is nearly impossible sinceRequestManager::createGuzzleClient()
is private and one had to recreate much of the code.It would be great when there'd be an easier way to do this in v1 or even in v2 where
FixtureData
has changed toRecordedResponse
.I would love to hear your opinion on this.
Beta Was this translation helpful? Give feedback.
All reactions