function TemplateProjectTestBase::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.

Overrides BuildTestBase::instantiateServer

1 call to TemplateProjectTestBase::instantiateServer()
TemplateProjectTestBase::createTestProject in core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php
Creates a test project from a given template and installs Drupal.

File

core/modules/package_manager/tests/src/Build/TemplateProjectTestBase.php, line 147

Class

TemplateProjectTestBase
Base class for tests which create a test site from a core project template.

Namespace

Drupal\Tests\package_manager\Build

Code

protected function instantiateServer($port, $working_dir = NULL) {
  $working_dir = $working_dir ?: $this->webRoot;
  $finder = new PhpExecutableFinder();
  $working_path = $this->getWorkingPath($working_dir);
  $server = [
    $finder->find(),
    '-S',
    '127.0.0.1:' . $port,
    '-d max_execution_time=' . static::MAX_EXECUTION_TIME,
    '-d disable_functions=set_time_limit',
    '-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(function ($output_type, $output) : void {
    if ($output_type === Process::ERR) {
      $this->serverErrorLog .= $output;
    }
  });
  // 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()));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.