Last active
August 30, 2019 16:42
-
-
Save peterlafferty/f7b32a1af79372cb76c85b2ec0773be9 to your computer and use it in GitHub Desktop.
example integration test in PHPUnit which starts the build in web server
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
<?php | |
use PHPUnit\Framework\TestCase; | |
use Symfony\Component\Process\Process; | |
use GuzzleHttp\Client; | |
class IntegrationTest extends TestCase | |
{ | |
/** @var Process */ | |
private static $process; | |
public static function setUpBeforeClass() | |
{ | |
self::$process = new Process("php -S localhost:8080 -t ."); | |
self::$process->start(); | |
usleep(100000); //wait for server to get going | |
} | |
public static function tearDownAfterClass() | |
{ | |
self::$process->stop(); | |
} | |
public function test404() | |
{ | |
$client = new Client(['http_errors' => false]); | |
$response = $client->request("GET", "http://localhost:8080"); | |
$this->assertEquals(404, $response->getStatusCode()); | |
} | |
public function test200() | |
{ | |
$client = new Client(['http_errors' => false]); | |
$response = $client->request("GET", "http://localhost:8080/testpage/"); | |
$this->assertEquals(200, $response->getStatusCode()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment