From 17139e2e5db887019fdc4d263610ad6e1836fae9 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Mon, 30 Aug 2021 15:52:56 -0500 Subject: [PATCH] Adds super basic integration test --- ...bServer_ChangedDefault_IntegrationTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/MockWebServer_ChangedDefault_IntegrationTest.php 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); + } + +}