Skip to content

Commit

Permalink
Adds super basic integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Aug 30, 2021
1 parent c9d806d commit 17139e2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/MockWebServer_ChangedDefault_IntegrationTest.php
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);
}

}

0 comments on commit 17139e2

Please sign in to comment.