Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit and Expand Error handling In CloudFlareAPI class #16

Open
5 tasks
aweingarten opened this issue Sep 8, 2015 · 3 comments
Open
5 tasks

Audit and Expand Error handling In CloudFlareAPI class #16

aweingarten opened this issue Sep 8, 2015 · 3 comments

Comments

@aweingarten
Copy link
Contributor

Business Requirements

  • As a use of the PHP SDK I want to get meaningful and typed exceptions thrown when a request does not succeed as expected.

Background

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
Copy link

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 aweingarten added this to the Beta Release milestone Sep 8, 2015
@aweingarten
Copy link
Contributor Author

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants