-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use donatj\MockWebServer\MockWebServer; | ||
use donatj\MockWebServer\Response; | ||
use donatj\MockWebServer\Responses\NotFoundResponse; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MockWebServer_ChangedDefault_IntegrationTest extends TestCase { | ||
|
||
public function testChangingDefaultResponse() { | ||
$server = new MockWebServer; | ||
$server->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); | ||
} | ||
|
||
} |