restforcephp
restforcephp copied to clipboard
Make GuzzleRestClient Mockable / Testable
https://github.com/eventfarm/restforcephp/blob/master/src/Rest/GuzzleRestClient.php#L34 uses the following construct:
public function setBaseUriForRestClient(string $baseUri): void {
$this->client = new \GuzzleHttp\Client($config); // $this->client is private
}
This makes impossible to test an app relying upon restforcephp because we can hardly¹ mock the responses.
- You shouldn't use absolute class namespace.
- The GuzzleHttp\Client is a dependency that should be passed as an argument
- With
$this->clientbeing private, we can't overload it.
Could you please improve the situation so that SF depending upon restforce can be tested?
¹ It's actually possible, but using a tons of boilerplate code and workarounds
Great suggestions!
You are more than welcome to submit a pull request with these improvements. As long as there are no backwards compatibility issues, I'm sure we could get it merged in a future release without any issues.