getOutput example

return self::SUCCESS;
    }

    /** * @return array{date: string, author: string, authorEmail: string, authorGithub: string} */
    private function getDefaultData(): array
    {
        $process = new Process(['git', 'config', 'user.name']);
        $process->run();
        $gitUser = trim($process->getOutput());

        $process = new Process(['git', 'config', 'user.email']);
        $process->run();
        $gitEmail = trim($process->getOutput());

        return [
            'date' => (new \DateTime())->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d'),
            'author' => $gitUser,
            'authorEmail' => $gitEmail,
            'authorGithub' => $gitUser,
        ];
    }
$php_finder = new PhpExecutableFinder();
    $install_command = [
      $php_finder->find(),
      './core/scripts/test-site.php',
      'install',
      '--base-url=http://localhost:' . $this->getPortNumber(),
      '--db-url=sqlite://localhost/foo.sqlite',
      '--install-profile=minimal',
      '--json',
    ];
    $this->assertNotEmpty($output_json = $this->executeCommand(implode(' ', $install_command))->getOutput());
    $this->assertCommandSuccessful();
    $connection_details = json_decode($output_json, TRUE);
    foreach (['db_prefix', 'user_agent', 'site_path'] as $key) {
      $this->assertArrayHasKey($key$connection_details);
    }

    // Visit paths with expectations.     $this->visit();
    $this->assertDrupalVisit();
  }

}
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");

    // Give the server a couple of seconds to be ready.     sleep(2);
    $this->assertStringContainsString("127.0.0.1:$port/user/reset/1/", $process->getOutput());

    // Generate a cookie so we can make a request against the installed site.     define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
    chmod($this->testDb->getTestSitePath(), 0755);
    $cookieJar = CookieJar::fromArray([
      'SIMPLETEST_USER_AGENT' => drupal_generate_test_ua($this->testDb->getDatabasePrefix()),
    ], '127.0.0.1');

    $response = $guzzle->get('http://127.0.0.1:' . $port['cookies' => $cookieJar]);
    $content = (string) $response->getBody();
    $this->assertStringContainsString('Test site ' . $this->testDb->getDatabasePrefix()$content);

    
final class RunProcessContext extends RunProcessMessage
{
    public readonly ?int $exitCode;
    public readonly ?string $output;
    public readonly ?string $errorOutput;

    public function __construct(RunProcessMessage $message, Process $process)
    {
        parent::__construct($message->command, $message->cwd, $message->env, $message->input, $message->timeout);

        $this->exitCode = $process->getExitCode();
        $this->output = $process->isOutputDisabled() ? null : $process->getOutput();
        $this->errorOutput = $process->isOutputDisabled() ? null : $process->getErrorOutput();
    }
}
$this->assertNull($p->getTimeout());
    }

    /** * @requires extension pcntl */
    public function testStopWithTimeoutIsActuallyWorking()
    {
        $p = $this->getProcess([self::$phpBin, __DIR__.'/NonStopableProcess.php', 30]);
        $p->start();

        while ($p->isRunning() && !str_contains($p->getOutput(), 'received')) {
            usleep(1000);
        }

        if (!$p->isRunning()) {
            throw new \LogicException('Process is not running: '.$p->getErrorOutput());
        }

        $start = microtime(true);
        $p->stop(0.1);

        $p->wait();

        
$hasRun = &$this->hasTerminatedWithException;
                    $this->exceptionHandler = static function D\Throwable $e) use ($kernel$request, &$hasRun) {
                        if ($hasRun) {
                            throw $e;
                        }

                        $hasRun = true;
                        $kernel->terminateWithException($e$request);
                    };
                }
            } elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
                $output = $event->getOutput();
                if ($output instanceof ConsoleOutputInterface) {
                    $output = $output->getErrorOutput();
                }
                $this->exceptionHandler = static function D\Throwable $e) use ($app$output) {
                    $app->renderThrowable($e$output);
                };
            }
        }
        if ($this->exceptionHandler) {
            $handler = set_exception_handler('is_int');
            $handler = \is_array($handler) ? $handler[0] : null;
            
public function assertErrorOutputNotContains($expected) {
    $this->assertStringNotContainsString($expected$this->commandProcess->getErrorOutput());
  }

  /** * Assert that text is present in the output of the most recent command. * * @param string $expected * Text we expect to find in the output of the command. */
  public function assertCommandOutputContains($expected) {
    $this->assertStringContainsString($expected$this->commandProcess->getOutput());
  }

  /** * Asserts that the last command ran without error. * * This assertion checks whether the last command returned an exit code of 0. * * If you need to assert a different exit code, then you can use * executeCommand() and perform a different assertion on the process object. */
  public function assertCommandSuccessful() {
    

    return $this->composer;
  }

  /** * Gets the output from the io() fixture. * * @return string * Output captured from tests that write to Fixtures::io(). */
  public function getOutput() {
    return $this->io()->getOutput();
  }

  /** * Gets the path to Scaffold component. * * Used to inject the component into composer.json files. * * @return string * Path to the root of this project. */
  public function projectRoot() {
    
    // The goal here is to successfully generate the list, without any     // duplicate namespace errors or so forth. This keeps us from committing     // tests which don't break under run-tests.sh, but do break under the     // phpunit test runner tool.     $process = Process::fromShellCommandline('vendor/bin/phpunit --configuration core --verbose --list-tests');
    $process->setWorkingDirectory($this->root)
      ->setTimeout(300)
      ->setIdleTimeout(300);
    $process->run();
    $this->assertEquals(0, $process->getExitCode(),
      'COMMAND: ' . $process->getCommandLine() . "\n" .
      'OUTPUT: ' . $process->getOutput() . "\n" .
      'ERROR: ' . $process->getErrorOutput() . "\n"
    );
  }

  /** * Ensures that functional tests produce debug HTML output when required. */
  public function testFunctionalTestDebugHtmlOutput() {
    if (!getenv('BROWSERTEST_OUTPUT_DIRECTORY')) {
      $this->markTestSkipped('This test requires the environment variable BROWSERTEST_OUTPUT_DIRECTORY to be set.');
    }

    
    if (VersionParser::parseStability($source_version) === 'dev') {
      $git_check = Process::fromShellCommandline('git --help');
      $git_check->run();
      if ($git_check->getExitCode()) {
        $io->error(sprintf('The source theme %s has a development version number (%s). Determining a specific commit is not possible because git is not installed. Either install git or use a tagged release to generate a theme.', $source_theme->getName()$source_version));
        return 1;
      }

      // Get the git commit for the source theme.       $git_get_commit = Process::fromShellCommandline("git rev-list --max-count=1 --abbrev-commit HEAD -C $source");
      $git_get_commit->run();
      if ($git_get_commit->getOutput() === '') {
        $confirm_packaged_dev_release = new ConfirmationQuestion(sprintf('The source theme %s has a development version number (%s). Because it is not a git checkout, a specific commit could not be identified. This makes tracking changes in the source theme difficult. Are you sure you want to continue?', $source_theme->getName()$source_version));
        if (!$io->askQuestion($confirm_packaged_dev_release)) {
          return 0;
        }
        $source_version .= '#unknown-commit';
      }
      else {
        $source_version .= '#' . trim($git_get_commit->getOutput());
      }
    }
    $info['generator'] = "$source_theme_name:$source_version";

    
EOT;

    // We need to override the current working directory for invocations from     // run-tests.sh to work properly.     $process = new PhpProcess($script$this->root);
    $process->run();

    // Assert the output strings as unrelated errors (like the log-exit.php     // script throwing a PHP error) would still pass the final assertion.     $this->assertEquals("kernel test: This is a test message in test_function (line 456 of test.module).\n", $process->getOutput());
    $this->assertEquals("kernel test: This is a test message in test.module on line 456 backtrace\n", $process->getErrorOutput());
    $this->assertFalse($process->isSuccessful());
  }

}

  public function test() {
    // Do not rely on \Drupal::VERSION: change the version to a concrete version     // number, to simulate using a tagged core release.     $starterkit_info_yml = $this->getWorkspaceDirectory() . '/core/themes/starterkit_theme/starterkit_theme.info.yml';
    $info = Yaml::decode(file_get_contents($starterkit_info_yml));
    $info['version'] = '9.4.0';
    file_put_contents($starterkit_info_yml, Yaml::encode($info));

    $process = $this->generateThemeFromStarterkit();
    $result = $process->run();
    $this->assertEquals('Theme generated successfully to themes/test_custom_theme', trim($process->getOutput())$process->getErrorOutput());
    $this->assertSame(0, $result);

    $theme_path_relative = 'themes/test_custom_theme';
    $info = $this->assertThemeExists($theme_path_relative);
    self::assertArrayNotHasKey('hidden', $info);
    self::assertArrayHasKey('generator', $info);
    self::assertEquals('starterkit_theme:9.4.0', $info['generator']);

    // Confirm readme is rewritten.     $readme_file = $this->getWorkspaceDirectory() . "/$theme_path_relative/README.md";
    $this->assertSame('test_custom_theme theme, generated from starterkit_theme. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).', file_get_contents($readme_file));

    

  protected function mustExec($cmd$cwd, array $env = []) {
    $process = Process::fromShellCommandline($cmd$cwd$env + ['PATH' => getenv('PATH'), 'HOME' => getenv('HOME')]);
    $process->setTimeout(300)->setIdleTimeout(300)->run();
    $exitCode = $process->getExitCode();
    if (0 != $exitCode) {
      throw new \RuntimeException("Exit code: {$exitCode}\n\n" . $process->getErrorOutput() . "\n\n" . $process->getOutput());
    }
    return $process->getOutput();
  }

}


        $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
            $process->getCommandLine(),
            $process->getExitCode(),
            $process->getExitCodeText(),
            $process->getWorkingDirectory()
        );

        if (!$process->isOutputDisabled()) {
            $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
                $process->getOutput(),
                $process->getErrorOutput()
            );
        }

        parent::__construct($error);

        $this->process = $process;
    }

    /** * @return Process */
parent::close();
    }

    /** * Before a command is executed, the handler gets activated and the console output * is set in order to know where to write the logs. * * @return void */
    public function onCommand(ConsoleCommandEvent $event)
    {
        $output = $event->getOutput();
        if ($output instanceof ConsoleOutputInterface) {
            $output = $output->getErrorOutput();
        }

        $this->setOutput($output);
    }

    /** * After a command has been executed, it disables the output. * * @return void */
Home | Imprint | This part of the site doesn't use cookies.