executeCommand example


class InstallTest extends BuildTestBase {

  public function testInstall() {
    $this->copyCodebase();
    $fs = new Filesystem();
    $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);

    // Composer tells you stuff in error output.     $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-interaction');
    $this->assertErrorOutputContains('Generating autoload files');

    // We have to stand up the server first so we can know the port number to     // pass along to the install command.     $this->standUpServer();

    $php_finder = new PhpExecutableFinder();
    $install_command = [
      $php_finder->find(),
      './core/scripts/test-site.php',
      'install',
      

    public function getAuthKeyword(): string
    {
        return 'CRAM-MD5';
    }

    /** * @see https://www.ietf.org/rfc/rfc4954.txt */
    public function authenticate(EsmtpTransport $client): void
    {
        $challenge = $client->executeCommand("AUTH CRAM-MD5\r\n", [334]);
        $challenge = base64_decode(substr($challenge, 4));
        $message = base64_encode($client->getUsername().' '.$this->getResponse($client->getPassword()$challenge));
        $client->executeCommand(sprintf("%s\r\n", $message)[235]);
    }

    /** * Generates a CRAM-MD5 response from a server challenge. */
    private function getResponse(#[\SensitiveParameter] string $secret, string $challenge): string     {
        if (\strlen($secret) > 64) {
            
$command = new DebugCommand('dev', __DIR__.'/Fixtures/Scenario1');
        $command->setHelperSet(new HelperSet([new FormatterHelper()]));
        $tester = new CommandTester($command);
        $tester->execute([]);
        $output = $tester->getDisplay();

        $this->assertStringContainsString('[ERROR] Dotenv component is not initialized', $output);
    }

    public function testScenario1InDevEnv()
    {
        $output = $this->executeCommand(__DIR__.'/Fixtures/Scenario1', 'dev');

        // Scanned Files         $this->assertStringContainsString('⨯ .env.local.php', $output);
        $this->assertStringContainsString('⨯ .env.dev.local', $output);
        $this->assertStringContainsString('⨯ .env.dev', $output);
        $this->assertStringContainsString('✓ .env.local', $output);
        $this->assertStringContainsString('✓ .env'.\PHP_EOL, $output);

        // Skipped Files         $this->assertStringNotContainsString('.env.prod', $output);
        $this->assertStringNotContainsString('.env.test', $output);
        
    // the branch, ensure that we no longer allow alpha dependencies.     $this->assertGreaterThanOrEqual(array_search($this->getCoreStability()static::STABILITY_ORDER)array_search(static::MINIMUM_STABILITY, static::STABILITY_ORDER));

    // Ensure that static::MINIMUM_STABILITY is the same as the least stable     // dependency.     // - We can't set it stricter than our least stable dependency.     // - We don't want to set it looser than we need to, because we don't want     // to in the future accidentally commit a dependency that regresses our     // actual stability requirement without us explicitly changing this     // constant.     $root = $this->getDrupalRoot();
    $process = $this->executeCommand("composer --working-dir=$root info --format=json");
    $this->assertCommandSuccessful();
    $installed = json_decode($process->getOutput(), TRUE);

    // A lookup of the numerical position of each of the stability terms.     $stability_order_indexes = array_flip(static::STABILITY_ORDER);

    $minimum_stability_order_index = $stability_order_indexes[static::MINIMUM_STABILITY];

    $exclude = [
      'drupal/core',
      'drupal/core-project-message',
      

        return $this->domain;
    }

    public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
    {
        try {
            $message = parent::send($message$envelope);
        } catch (TransportExceptionInterface $e) {
            if ($this->started) {
                try {
                    $this->executeCommand("RSET\r\n", [250]);
                } catch (TransportExceptionInterface) {
                    // ignore this exception as it probably means that the server error was final                 }
            }

            throw $e;
        }

        if ($this->mtaResult && $messageId = $this->parseMessageId($this->mtaResult)) {
            $message->setMessageId($messageId);
        }

        

  protected function assertDrupalVersion(string $expectedVersion, string $dir): void {
    $drupal_php_path = $dir . '/core/lib/Drupal.php';
    $this->assertFileExists($drupal_php_path);

    // Read back the Drupal version that was set and assert it matches     // expectations     $this->executeCommand("php -r 'include \"$drupal_php_path\"; print \Drupal::VERSION;'");
    $this->assertCommandSuccessful();
    $this->assertCommandOutputContains($expectedVersion);
  }

  /** * Find all the composer.json files for components. * * @param string $drupal_root * The Drupal root directory. * * @return \Symfony\Component\Finder\Finder * A Finder object with all the composer.json files for components. */

class BuildTestTest extends BuildTestBase {

  /** * Ensure that workspaces work. */
  public function testWorkspace() {
    $test_directory = 'test_directory';

    // Execute an empty command through the shell to build out a working     // directory.     $process = $this->executeCommand('', $test_directory);
    $this->assertCommandSuccessful();

    // Assert that our working directory exists and is in use by the process.     $workspace = $this->getWorkspaceDirectory();
    $working_path = $workspace . '/' . $test_directory;
    $this->assertDirectoryExists($working_path);
    $this->assertEquals($working_path$process->getWorkingDirectory());
  }

  /** * @covers ::copyCodebase */
/** * @covers ::instantiateServer */
  public function testHtRouter() {
    $sqlite = (new \PDO('sqlite::memory:'))->query('select sqlite_version()')->fetch()[0];
    if (version_compare($sqlite, Tasks::SQLITE_MINIMUM_VERSION) < 0) {
      $this->markTestSkipped();
    }

    $this->copyCodebase();
    $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
    $this->assertErrorOutputContains('Generating autoload files');
    $this->installQuickStart('minimal');
    $this->formLogin($this->adminUsername, $this->adminPassword);
    $this->visit('/.well-known/change-password');
    $this->assertDrupalVisit();
    $url = $this->getMink()->getSession()->getCurrentUrl();
    $this->assertEquals('http://localhost:' . $this->getPortNumber() . '/user/1/edit', $url);
  }

}
protected function setUp(): void
    {
        $this->configGetCommand = $this->getConfigGetCommand();
    }

    /** * @dataProvider configFormatJsonProvider */
    public function testConfigGetJson(string $key, string $format, string $output): void
    {
        $commandOutput = $this->executeCommand($key$format);
        static::assertJsonStringEqualsJsonString($commandOutput$output);
    }

    public static function configFormatJsonProvider(): \Generator
    {
        // config key, format, output         yield 'test scalar value' => ['foo.bar.testBoolTrue', 'json', '{"foo.bar.testBoolTrue":true}'];
        yield 'test array' => ['foo.bar', 'json', '{"testBoolFalse":false,"testInt":123,"testBoolTrue":true,"testString":"test"}'];
        yield 'test array and json-pretty format' => ['foo.bar', 'json-pretty', '{"testBoolFalse":false,"testInt":123,"testBoolTrue":true,"testString":"test"}'];
    }

    

    public function getAuthKeyword(): string
    {
        return 'XOAUTH2';
    }

    /** * @see https://developers.google.com/google-apps/gmail/xoauth2_protocol#the_sasl_xoauth2_mechanism */
    public function authenticate(EsmtpTransport $client): void
    {
        $client->executeCommand('AUTH XOAUTH2 '.base64_encode('user='.$client->getUsername()."\1auth=Bearer ".$client->getPassword()."\1\1")."\r\n", [235]);
    }
}
/** * Install a Drupal site using the quick start feature. * * @param string $profile * Drupal profile to install. * @param string $working_dir * (optional) A working directory relative to the workspace, within which to * execute the command. Defaults to the workspace directory. */
  public function installQuickStart($profile$working_dir = NULL) {
    $php_finder = new PhpExecutableFinder();
    $install_process = $this->executeCommand($php_finder->find() . ' ./core/scripts/drupal install ' . $profile$working_dir);
    $this->assertCommandOutputContains('Username:');
    preg_match('/Username: (.+)\vPassword: (.+)/', $install_process->getOutput()$matches);
    $this->assertNotEmpty($this->adminUsername = $matches[1]);
    $this->assertNotEmpty($this->adminPassword = $matches[2]);
  }

  /** * Helper that uses Drupal's user/login form to log in. * * @param string $username * Username. * @param string $password * Password. * @param string $working_dir * (optional) A working directory within which to login. Defaults to the * workspace directory. */
'active' => false,
            'installedAt' => new \DateTimeImmutable('2019-05-23T00:00:00.000001Z'),
            'upgradeVersion' => '6.0.0',
            'name' => 'Shopware Next',
            'label' => 'swn',
            'version' => '5.5.3',
            'author' => 'Shopware AG',
        ]);

        $this->setupEntityCollection($entities);

        $commandTester = $this->executeCommand([]);
        static::assertSame(0, $commandTester->getStatusCode());
        static::assertStringEqualsFile(
            __DIR__ . '/../_assertion/PluginListCommandTest-testCommand.txt',
            implode("\n", array_map('trim', explode("\n", trim($commandTester->getDisplay())))) . "\n"
        );
    }

    public function testFilter(): void
    {
        $filterValue = 'shopware-is-love';

        

  public function testReleaseTagging(string $tag, string $constraint): void {
    $this->copyCodebase();
    $drupal_root = $this->getWorkspaceDirectory();

    // Set the core version.     Composer::setDrupalVersion($drupal_root$tag);
    $this->assertDrupalVersion($tag$drupal_root);

    // Emulate the release script.     // @see https://github.com/xjm/drupal_core_release/blob/main/tag.sh     $this->executeCommand("COMPOSER_ROOT_VERSION=\"$tag\" composer update drupal/core*");
    $this->assertCommandSuccessful();
    $this->assertErrorOutputContains('generateComponentPackages');

    // Find all the components.     $component_finder = $this->getComponentPathsFinder($drupal_root);

    // Loop through all the component packages.     /** @var \Symfony\Component\Finder\SplFileInfo $composer_json */
    foreach ($component_finder->getIterator() as $composer_json) {
      $composer_json_data = json_decode(file_get_contents($composer_json->getPathname()), TRUE);
      $requires = array_merge(
        
$this->addAuthenticator($authenticator);
        }
    }

    public function addAuthenticator(AuthenticatorInterface $authenticator): void
    {
        $this->authenticators[] = $authenticator;
    }

    public function executeCommand(string $command, array $codes): string
    {
        return [250] === $codes && str_starts_with($command, 'HELO ') ? $this->doEhloCommand() : parent::executeCommand($command$codes);
    }

    final protected function getCapabilities(): array
    {
        return $this->capabilities;
    }

    private function doEhloCommand(): string
    {
        try {
            $response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain())[250]);
        }

  protected function setUp(): void {
    $sqlite = (new \PDO('sqlite::memory:'))->query('select sqlite_version()')->fetch()[0];
    if (version_compare($sqlite, Tasks::SQLITE_MINIMUM_VERSION) < 0) {
      $this->markTestSkipped();
    }
    parent::setUp();
    $php_executable_finder = new PhpExecutableFinder();
    $this->php = $php_executable_finder->find();
    $this->copyCodebase();
    $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
    chdir($this->getWorkingPath());
  }

  /** * Generates PHP process to generate a theme from core's starterkit theme. * * @return \Symfony\Component\Process\Process * The PHP process */
  private function generateThemeFromStarterkit($env = NULL) : Process {
    $install_command = [
      
Home | Imprint | This part of the site doesn't use cookies.