View source
<?php
namespace Drupal\Tests\system\Kernel\Scripts;
use Drupal\Core\Command\DbDumpCommand;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Console\Tester\CommandTester;
class DbDumpCommandTest extends KernelTestBase {
public static $modules = [
'system',
];
public function setUp() {
parent::setUp();
if (Database::getConnection()
->databaseType() !== 'mysql') {
$this
->markTestSkipped("Skipping test since the DbDumpCommand is currently only compatible with MySQL");
}
$this
->installSchema('system', 'router');
$connection = $this->container
->get('database');
$connection
->insert('router')
->fields([
'name',
'path',
'pattern_outline',
])
->values([
'test',
'test',
'test',
])
->execute();
}
public function testDbDumpCommand() {
$command = new DbDumpCommand();
$command_tester = new CommandTester($command);
$command_tester
->execute([]);
$output = $command_tester
->getDisplay();
$this
->assertContains("createTable('router", $output, 'Table router found');
$this
->assertContains("insert('router", $output, 'Insert found');
$this
->assertContains("'name' => 'test", $output, 'Insert name field found');
$this
->assertContains("'path' => 'test", $output, 'Insert path field found');
$this
->assertContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field found');
}
public function testSchemaOnly() {
$command = new DbDumpCommand();
$command_tester = new CommandTester($command);
$command_tester
->execute([
'--schema-only' => 'router',
]);
$output = $command_tester
->getDisplay();
$this
->assertContains("createTable('router", $output, 'Table router found');
$this
->assertNotContains("insert('router", $output, 'Insert not found');
$this
->assertNotContains("'name' => 'test", $output, 'Insert name field not found');
$this
->assertNotContains("'path' => 'test", $output, 'Insert path field not found');
$this
->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found');
$command_tester
->execute([
'--schema-only' => 'route.*',
]);
$output = $command_tester
->getDisplay();
$this
->assertContains("createTable('router", $output, 'Table router found');
$this
->assertNotContains("insert('router", $output, 'Insert not found');
$this
->assertNotContains("'name' => 'test", $output, 'Insert name field not found');
$this
->assertNotContains("'path' => 'test", $output, 'Insert path field not found');
$this
->assertNotContains("'pattern_outline' => 'test", $output, 'Insert pattern_outline field not found');
}
}