Last active
August 29, 2015 14:02
-
-
Save jakzal/a3915d096eca42a69b79 to your computer and use it in GitHub Desktop.
PHP Server Behat Context
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 Behat\Behat\Context\Context; | |
use Symfony\Component\Process\Process; | |
class PhpServerContext implements Context | |
{ | |
/** | |
* @var Process | |
*/ | |
private static $phpServer; | |
/** | |
* @BeforeSuite | |
*/ | |
public static function startPhpServer() | |
{ | |
self::$phpServer = new Process('php -S localhost:8000 features/application/index.php'); | |
self::$phpServer->start(); | |
$tries = 10; | |
while (!($result = @file_get_contents('http://localhost:8000/')) && $tries-- > 0) { | |
usleep(10000); | |
} | |
} | |
/** | |
* @AfterSuite | |
*/ | |
public static function stopPhpServer() | |
{ | |
self::$phpServer->stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's also an extension for this: https://github.com/ciaranmcnulty/behat-localwebserverextension