PATH_SEPARATOR . '/path/to/zend/library/');
include_once 'Zend/Http/Client.php';
class ZendHttpTest extends PHPUnit_Framework_TestCase
{
public function testLoadGoogle()
{
$client = new Zend_Http_Client('http://www.google.com.au/'); A
$response = $client->request(); A
$this->assertContains('', $response->getBody()); A
}
public function testQueryGoogle()
{
$client = new Zend_Http_Client(
'http://www.google.com.au/search?q=zend+framework'); B
$response = $client->request(); B
$this->assertContains('framework.zend.com/',
$response->getBody()); B
}
}
A Test makes a request to Google and then makes sure it contains some html
B Test makes a search query request to Google and makes sure a string appears in the results
The similarities between the code for this and the previous Selenium test are pretty evident so there really
isn't any need to do much more than run the test. We can see the results in figure 10.7.
Figure 10.7 One failure on the first run of our unit test.
One failure due to the typo "" instead of "", so after correcting that let's check the results of running
the test again in figure 10.8
.
Figure 10.8 The final unit test is successful.
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co.
Pages:
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301