Re: Re: HTTP_Request2

From: Date: Wed, 29 Oct 2008 02:53:30 +0000
Subject: Re: Re: HTTP_Request2
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-50963@lists.php.net to get a copy of this message
> > >>> >> Don't forget that if there was a mock http adapter which can provide >> canned/simulated responses, loads of packages in PEAR just got a lot more >> easy to unit test. >> >> > yes but... > what theses responses will contain ? static text ? > Are you going to implement a mock HTTP server to build relevant responses ? > > But you have a point, client/sever applications are hard to unit-test, this > is the cruel real world, there are many, differents, erratic http servers in > the interweb... > Absolutely :) Think about testing packages like XML_RPC2 - it currently relies on live servers and there's network latency - slow tests, if the server falls over you spend time thinking "arggh, I broke something" when its not your fault. XML_RPC2 doesn't care about the thousands of little edge cases that HTTP_Request2 can handle (and presumably have unit tested also :P). It only cares about class MockErroredHTTPRequest extends MockHTTPRequestDriver { public function get() { throw new HTTP_Request2_Exception("BLARGH"); } } class MockSuccessHTTPRequest extends MockHTTPRequestDriver { public function get() { return file_get_contents('my_canned_response.xml'); } } *snip* public function testShouldGracefullyFailWhenHTTPProblemsExists() { $client = new XML_RPC2(); $client->setDriver(new HTTP_Request2(new MockErroredHTTPRequest()); try { $client->doSomething(); } catch (HTTP_Request2_Exception $e) { $this->fail("Allowed an exception to bubble up too far!"); } } .. or similar

« previous php.pear.dev (#50963) next »