Excluded or removed tests relying on actual webserver routing

The "sanitychecks" group excludes through phpunit.xml.dist.
Removed RestfulService->testHttpErrorWithoutCache()
since its not sufficiently isolated in terms of testing.
Has been refactored in 3.x, but too intrusive to backport.

Changes mainly necessary to get Travis builds passing,
since we don't want to start mucking around with
dynamically generated file-to-url mappings just to
get *unit* tests passing - as opposed to integration-testing
the whole environment incl. webserver.
This commit is contained in:
Ingo Schommer 2012-11-28 15:35:09 +01:00
parent 7db928ba17
commit 326036a501
2 changed files with 8 additions and 32 deletions

View File

@ -8,6 +8,8 @@
* @todo Exclude this test from a standard test run - not all test environments
* might have a webserver installed, or have it accessible for HTTP requests
* from localhost.
*
* @group sanitychecks
*
* @package sapphire
* @subpackage tests

View File

@ -93,14 +93,14 @@ class RestfulServiceTest extends SapphireTest {
* @expectedException PHPUnit_Framework_Error
*/
function testIncorrectData() {
$connection = new RestfulService(Director::absoluteBaseURL(), 0);
$test1 = $connection->request('RestfulServiceTest_Controller/invalid?usetestmanifest=1&flush=1');
$connection = new RestfulServiceTest_MockRestfulService(Director::absoluteBaseURL(), 0);
$test1 = $connection->request('RestfulServiceTest_Controller/invalid');
$test1->xpath("\\fail");
}
function testHttpErrorWithoutCache() {
$connection = new RestfulService(Director::absoluteBaseURL(), 0);
$response = $connection->request('RestfulServiceTest_Controller/httpErrorWithoutCache?usetestmanifest=1&flush=1');
$connection = new RestfulServiceTest_MockRestfulService(Director::absoluteBaseURL(), 0);
$response = $connection->request('RestfulServiceTest_Controller/httpErrorWithoutCache');
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->getCachedBody());
@ -108,30 +108,6 @@ class RestfulServiceTest extends SapphireTest {
}
function testHttpErrorWithCache() {
$subUrl = 'RestfulServiceTest_Controller/httpErrorWithCache?usetestmanifest=1&flush=1';
$connection = new RestfulService(Director::absoluteBaseURL(), 0);
$this->createFakeCachedResponse($connection, $subUrl);
$response = $connection->request($subUrl);
$this->assertEquals(400, $response->getStatusCode());
$this->assertEquals("Cache response body",$response->getCachedBody());
$this->assertContains("<error>HTTP Error</error>", $response->getBody());
}
/**
* Simulate cached response file for testing error requests that are supposed to have cache files
*/
private function createFakeCachedResponse($connection, $subUrl) {
$fullUrl = $connection->getAbsoluteRequestURL($subUrl);
$cachedir = TEMP_FOLDER; // Default silverstripe cache
$cache_file = md5($fullUrl); // Encoded name of cache file
$cache_path = $cachedir."/xmlresponse_$cache_file";
$cacheResponse = new RestfulService_Response("Cache response body");
$store = serialize($cacheResponse);
file_put_contents($cache_path, $store);
}
}
class RestfulServiceTest_Controller extends Controller {
@ -218,7 +194,7 @@ XML;
class RestfulServiceTest_MockRestfulService extends RestfulService {
public $session = null;
public function request($subURL = '', $method = "GET", $data = null, $headers = null) {
if(!$this->session) {
@ -263,7 +239,6 @@ class RestfulServiceTest_MockRestfulService extends RestfulService {
else $postVars = $data;
$responseFromDirector = Director::test($url, $postVars, $this->session, $method, $body, $headers);
$response = new RestfulService_Response(
$responseFromDirector->getBody(),
$responseFromDirector->getStatusCode()
@ -271,5 +246,4 @@ class RestfulServiceTest_MockRestfulService extends RestfulService {
return $response;
}
}
?>
}