You are here

public function BuildTestTest::testPortMany in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php \Drupal\BuildTests\Framework\Tests\BuildTestTest::testPortMany()

@covers ::findAvailablePort

File

core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php, line 132

Class

BuildTestTest
@coversDefaultClass \Drupal\BuildTests\Framework\BuildTestBase @group Build

Namespace

Drupal\BuildTests\Framework\Tests

Code

public function testPortMany() {
  $iterator = (new Finder())
    ->in($this
    ->getDrupalRoot())
    ->ignoreDotFiles(FALSE)
    ->exclude([
    'sites/simpletest',
  ])
    ->path('/^.ht.router.php$/')
    ->getIterator();
  $this
    ->copyCodebase($iterator);

  /** @var \Symfony\Component\Process\Process[] $processes */
  $processes = [];
  $count = 15;
  for ($i = 0; $i <= $count; $i++) {
    $port = $this
      ->findAvailablePort();
    $this
      ->assertArrayNotHasKey($port, $processes, 'Port ' . $port . ' was already in use by a process.');
    $processes[$port] = $this
      ->instantiateServer($port);
    $this
      ->assertNotEmpty($processes[$port]);
    $this
      ->assertTrue($processes[$port]
      ->isRunning(), 'Process on port ' . $port . ' is not still running.');
    $this
      ->assertFalse($this
      ->checkPortIsAvailable($port));
  }

  // Clean up after ourselves.
  foreach ($processes as $process) {
    $process
      ->stop();
  }
}