Skip to content

Commit

Permalink
Merge branch 'freekmurze-start-server'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed May 26, 2017
2 parents e107082 + cc32571 commit a48e984
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
</testsuite>
</testsuites>
<php>
<env name="TEST_SERVER_URL" value="http://your-test-server-url.dev"/>
<env name="TEST_SERVER_PORT" value="9000"/>
</php>
</phpunit>
27 changes: 26 additions & 1 deletion tests/ZttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

class ZttpTest extends TestCase
{
public static function setUpBeforeClass()
{
ZttpServer::start();
}

function url($url)
{
return vsprintf('%s/%s', [
rtrim(getenv('TEST_SERVER_URL'), '/'),
'http://localhost:' . getenv('TEST_SERVER_PORT'),
ltrim($url, '/'),
]);
}
Expand Down Expand Up @@ -368,3 +373,23 @@ function can_check_if_a_response_is_server_error()
$this->assertFalse($response->isClientError());
}
}

class ZttpServer
{
static function start()
{
if (! file_exists(__DIR__ . '/server/vendor')) {
exec('cd "' . __DIR__ . '/server"; composer install');
}

$pid = exec('php -S ' . 'localhost:' . getenv('TEST_SERVER_PORT') . ' -t ./tests/server/public > /dev/null 2>&1 & echo $!');

while (@file_get_contents('http://localhost:' . getenv('TEST_SERVER_PORT') . '/get') === false) {
usleep(1000);
}

register_shutdown_function(function () use ($pid) {
exec('kill ' . $pid);
});
}
}

0 comments on commit a48e984

Please sign in to comment.