diff --git a/test/MockWebServer_ChangedDefault_IntegrationTest.php b/test/MockWebServer_ChangedDefault_IntegrationTest.php new file mode 100644 index 0000000..85edafc --- /dev/null +++ b/test/MockWebServer_ChangedDefault_IntegrationTest.php @@ -0,0 +1,46 @@ +start(); + + $server->setResponseOfPath('funk', new Response('fresh')); + $path = $server->getUrlOfResponse(new Response('fries')); + + $content = file_get_contents($server->getServerRoot() . '/PageDoesNotExist'); + $result = json_decode($content, true); + $this->assertStringContainsString('200 OK', $http_response_header[0]); + $this->assertSame('/PageDoesNotExist', $result['PARSED_REQUEST_URI']['path']); + + // try with a 404 + $server->setDefaultResponse(new NotFoundResponse); + + $content = file_get_contents($server->getServerRoot() . '/PageDoesNotExist', false, stream_context_create([ + 'http' => [ 'ignore_errors' => true ] // allow reading 404s + ])); + + $this->assertStringContainsString('404 Not Found', $http_response_header[0]); + $this->assertContains('HTTP/1.0 404 Not Found', $http_response_header); + $this->assertSame("VND.DonatStudios.MockWebServer: Resource '/PageDoesNotExist' not found!\n", $content); + + // try with a custom response + $server->setDefaultResponse(new Response('cool beans')); + $content = file_get_contents($server->getServerRoot() . '/BadUrlBadTime'); + $this->assertSame('cool beans', $content); + + // ensure non-404-ing pages countinue to work as expected + $content = file_get_contents($server->getServerRoot() . '/funk'); + $this->assertSame('fresh', $content); + + $content = file_get_contents($path); + $this->assertSame('fries', $content); + } + +}