function BuildTestBase::instantiateServer
Same name in other branches
- 9 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::instantiateServer()
- 10 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php \Drupal\BuildTests\Framework\BuildTestBase::instantiateServer()
- 11.x 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 416
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 < 1000; $i++) {
if (!$this->checkPortIsAvailable($port)) {
return $ps;
}
usleep(1000);
}
throw new \RuntimeException(sprintf("Unable to start the web server.\nERROR OUTPUT:\n%s", $ps->getErrorOutput()));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.