d8-contrib-modules / cloudflarephpsdk

PHP SDK For interfacing with CloudFlare's API
8 stars 19 forks source link

Audit and Expand Error handling In CloudFlareAPI class #16

Open aweingarten opened 9 years ago

aweingarten commented 9 years ago

Business Requirements

The PHP SDK attempts to consolidate as much exception handling into a central location here: https://github.com/d8-contrib-modules/cloudflarephpsdk/blob/master/src/ApiEndpoints/CloudFlareAPI.php#L123

The code is designed to throw typed exceptions when a problem happens and expects the implementing code to handle these exceptions: https://github.com/d8-contrib-modules/cloudflarephpsdk/tree/master/src/Exceptions

Technical Requirements

mradcliffe commented 9 years ago

You could probably add tests that mock Guzzle, and force a specific response exception to be thrown.

I think....

$client = $this->getMockBuilder('\GuzzleHttp\Client')
   ->disableOriginalConstructor()
   ->getMock();
$client->expects($this->any())
   ->method('request')
   // Probably need to pass in some mocks into the exception object too.
   ->will($this->throwException(new \GuzzleHttp\Exception\RequestException));

Also, depending on guzzle "dev-master" might not be the best for stability.

aweingarten commented 9 years ago

@mradcliffe: I like the way you think. There are some primitive phpunit tests that have been added along those lines.

The constructor allows a mock object to be passed in: https://github.com/d8-contrib-modules/cloudflarephpsdk/blob/master/src/ApiEndpoints/CloudFlareAPI.php#L60

See tests here:

any chance you are interested in digging into this issue?

On the issue of tracking dev-master. You are correct. I'm going to add an issue to pin to a version for beta.

mradcliffe commented 9 years ago

I probably won't be able to get to it soon, but if I can, I'll fork and submit a Pull Request. I have been enjoying writing tests these days.