While you do not need a framework, the testing framework should still use Mock objects, and you should then have your code handle the functions accordingly. For instance, your libraries need to do something on the 404 error. Do not test that the HTML error code is 404, but rather that your libraries behave correctly.
class YourHTTPClass
{
private $HttpResponseCode;
public function getPage($URL, $Method)
{
// Do some code to get the page, set the error etc.
}
public function getHttpResponseCode()
{
return $this->HttpResponseCode;
}
...
}
PHPUnit Tests:
class YourHTTPClass_Test extends \PHPUnit_Framework_TestCase
{
public function testHTMLError404()
{
// Create a stub for the YourHTTPClass.
$stub = $this->getMock('YourHTTPClass');
// Configure the stub.
$stub->expects($this->any())
->method('getHttpResponseCode')
->will($this->returnValue(404));
// Calling $stub->getHttpResponseCode() will now return 404
$this->assertEquals(404, $stub->getHttpResponseCode('http://Bad_Url.com', 'GET'));
// Actual URL does not matter as external call will not be done with the mock
}
public function testHTMLError505()
{
// Create a stub for the YourHTTPClass.
$stub = $this->getMock('YourHTTPClass');
// Configure the stub.
$stub->expects($this->any())
->method('getHttpResponseCode')
->will($this->returnValue(505));
// Calling $stub->getHttpResponseCode() will now return 505
$this->assertEquals(505, $stub->getHttpResponseCode('http://Bad_Url.com',
}
This way you have tested that your code will handle the various return codes. With the mock objects, you may define multiple access options, or use data providers, etc... to generate the different error codes.
You will know that your code will be able to handle any of the errors, without needing to go to external web services to validate the errors.
To test your code that gets data, you would do something similar where you would actually mock the GET function to return known information, so you could test the code getting the results.