DbDumpCommand example


  protected function getCommandName(InputInterface $input): ?string {
    return 'dump-database-d8-mysql';
  }

  /** * {@inheritdoc} */
  protected function getDefaultCommands(): array {
    // Even though this is a single command, keep the HelpCommand (--help).     $default_commands = parent::getDefaultCommands();
    $default_commands[] = new DbDumpCommand();
    return $default_commands;
  }

  /** * {@inheritdoc} * * Overridden so the application doesn't expect the command name as the first * argument. */
  public function getDefinition(): InputDefinition {
    $definition = parent::getDefinition();
    
// Create a table with a field type not defined in     // \Drupal\Core\Database\Schema::getFieldTypeMap.     $table_name = $connection->getPrefix() . 'foo';
    $sql = "create table if not exists `$table_name` (`test` datetime NOT NULL);";
    $connection->query($sql)->execute();
  }

  /** * Tests the command directly. */
  public function testDbDumpCommand() {
    $command = new DbDumpCommand();
    $command_tester = new CommandTester($command);
    $command_tester->execute([]);

    // Assert that insert exists and that some expected fields exist.     $output = $command_tester->getDisplay();
    $this->assertStringContainsString("createTable('router", $output, 'Table router found');
    $this->assertStringContainsString("insert('router", $output, 'Insert found');
    $this->assertStringContainsString("'name' => 'test", $output, 'Insert name field found');
    $this->assertStringContainsString("'path' => 'test", $output, 'Insert path field found');
    $this->assertStringContainsString("'pattern_outline' => 'test", $output, 'Insert pattern_outline field found');
    $this->assertStringContainsString("// phpcs:ignoreFile", $output);
    

  public function __construct() {
    parent::__construct('Database Tools', \Drupal::VERSION);
  }

  /** * {@inheritdoc} */
  protected function getDefaultCommands(): array {
    $default_commands = parent::getDefaultCommands();
    $default_commands[] = new DbDumpCommand();
    $default_commands[] = new DbImportCommand();
    return $default_commands;
  }

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