restforcephp icon indicating copy to clipboard operation
restforcephp copied to clipboard

Make GuzzleRestClient Mockable / Testable

Open drzraf opened this issue 4 years ago • 1 comments

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.

  1. You shouldn't use absolute class namespace.
  2. The GuzzleHttp\Client is a dependency that should be passed as an argument
  3. With $this->client being 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

drzraf avatar Feb 04 '22 18:02 drzraf

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.

jasonraimondi avatar Feb 04 '22 19:02 jasonraimondi