protected function BuildTestBase::instantiateServer in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::instantiateServer()
Do the work of making a server process.
Test authors should call visit() or assertVisit() instead.
When initializing the server, if '.ht.router.php' exists in the root, it is leveraged. If testing with a version of Drupal before 8.5.x., this file does not exist.
Parameters
int $port: The port number for the server.
string|null $working_dir: (optional) Server docroot relative to the workspace filesystem. Defaults to the workspace directory.
Return value
\Symfony\Component\Process\Process The server process.
Throws
\RuntimeException Thrown if we were unable to start a web server.
2 calls to BuildTestBase::instantiateServer()
- BuildTestBase::standUpServer in core/
tests/ Drupal/ BuildTests/ Framework/ BuildTestBase.php - Makes a local test server using PHP's internal HTTP server.
- BuildTestTest::testPortMany in core/
tests/ Drupal/ BuildTests/ Framework/ Tests/ BuildTestTest.php - @covers ::findAvailablePort
File
- core/
tests/ Drupal/ BuildTests/ Framework/ BuildTestBase.php, line 410
Class
- BuildTestBase
- Provides a workspace to test build processes.
Namespace
Drupal\BuildTests\FrameworkCode
protected function instantiateServer($port, $working_dir = NULL) {
$finder = new PhpExecutableFinder();
$working_path = $this
->getWorkingPath($working_dir);
$server = [
$finder
->find(),
'-S',
self::$hostName . ':' . $port,
'-t',
$working_path,
];
if (file_exists($working_path . DIRECTORY_SEPARATOR . '.ht.router.php')) {
$server[] = $working_path . DIRECTORY_SEPARATOR . '.ht.router.php';
}
$ps = new Process($server, $working_path);
$ps
->setIdleTimeout(30)
->setTimeout(30)
->start();
// Wait until the web server has started. It is started if the port is no
// longer available.
for ($i = 0; $i < 50; $i++) {
usleep(100000);
if (!$this
->checkPortIsAvailable($port)) {
return $ps;
}
}
throw new \RuntimeException(sprintf("Unable to start the web server.\nCMD: %s \nCODE: %d\nSTATUS: %s\nOUTPUT:\n%s\n\nERROR OUTPUT:\n%s", $ps
->getCommandLine(), $ps
->getExitCode(), $ps
->getStatus(), $ps
->getOutput(), $ps
->getErrorOutput()));
}