Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.1

Request #15629 Add ability to set exception to be thrown in mock adapter
Submitted: 2009-01-13 21:58 UTC Modified: 2009-01-23 13:07 UTC
From: gauthierm Assigned: avb
Status: Closed Package: HTTP_Request2 (version 0.2.0)
PHP Version: 5.2.6 OS: Irrelevant
Roadmaps: 0.3.0    
Subscription  


 [2009-01-13 21:58 UTC] gauthierm (Michael Gauthier)
Description: ------------ The HTTP_Request2::send() method throws a HTTP_Request2_Exception (for example if the request times out). There's currently no way to mock that exception so it can be tested by users of HTTP_Request2. Test script: --------------- What would be nice is making the method: addResponse($response, $message = null, $code = null) The optional $message parameter could be a string or a HTTP_Request2_Exception. If the parameter(s) are specified, sendRequest() would throw an exception for the request instead of returning the response.

Comments

 [2009-01-15 09:31 UTC] doconnor (Daniel O'Connor)
Want to make a patch which extends HTTP_Request2_Adapter_Mock? HTTP_Request2_Adapter_AngryMock function addResponse() function addNastyException() ?
 [2009-01-15 09:35 UTC] avb (Alexey Borzov)
I think that it would be sufficient to change addResponse() to accept instances of HTTP_Request2_Exception and sendRequest() to either return or throw whatever is in $this->responses. No sense making a separate class.
 [2009-01-23 13:07 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. ------------------------------------------ Made it a bit simpler than in the proposed patch since we obviously can't throw an Exception and return a Response at the same time. Thanks!