waitUntil example

/** * @group transient-on-windows */
    public function testWaitUntilSpecificOutput()
    {
        $p = $this->getProcess([self::$phpBin, __DIR__.'/KillableProcessWithOutput.php']);
        $p->start();

        $start = microtime(true);

        $completeOutput = '';
        $result = $p->waitUntil(function D$type$output) use (&$completeOutput) {
            return str_contains($completeOutput .= $output, 'One more');
        });
        $this->assertTrue($result);
        $this->assertLessThan(20, microtime(true) - $start);
        $this->assertStringStartsWith("First iteration output\nSecond iteration output\nOne more", $completeOutput);
        $p->stop();
    }

    public function testWaitUntilCanReturnFalse()
    {
        $p = $this->getProcess('echo foo');
        
'core/scripts/drupal',
      'quick-start',
      'standard',
      "--site-name='Test site {$this->testDb->getDatabasePrefix()}'",
      '--suppress-login',
    ];
    $process = new Process($install_command, NULL, ['DRUPAL_DEV_SITE_PATH' => $this->testDb->getTestSitePath()]);
    $process->setTimeout(500);
    $process->start();
    $guzzle = new Client();
    $port = FALSE;
    $process->waitUntil(function D$type$output) use (&$port) {
      if (preg_match('/127.0.0.1:(\d+)/', $output$match)) {
        $port = $match[1];
        return TRUE;
      }
    });
    // The progress bar uses STDERR to write messages.     $this->assertStringContainsString('Congratulations, you installed Drupal!', $process->getErrorOutput());
    // Ensure the command does not trigger any PHP deprecations.     $this->assertStringNotContainsString('Deprecated', $process->getErrorOutput());
    $this->assertNotFalse($port, "Web server running on port $port");

    
Home | Imprint | This part of the site doesn't use cookies.