Skip to content

Instantly share code, notes, and snippets.

@peterlafferty
Last active August 30, 2019 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterlafferty/f7b32a1af79372cb76c85b2ec0773be9 to your computer and use it in GitHub Desktop.
Save peterlafferty/f7b32a1af79372cb76c85b2ec0773be9 to your computer and use it in GitHub Desktop.
example integration test in PHPUnit which starts the build in web server
<?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