class SqlTest
Same name in this branch
- 9 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest
- 11.x core/modules/migrate/tests/src/Kernel/Plugin/id_map/SqlTest.php \Drupal\Tests\migrate\Kernel\Plugin\id_map\SqlTest
- 10 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest
- 10 core/modules/migrate/tests/src/Kernel/Plugin/id_map/SqlTest.php \Drupal\Tests\migrate\Kernel\Plugin\id_map\SqlTest
- 8.9.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest
Tests that the migrate map table is created.
@group migrate
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase implements \Drupal\migrate\MigrateMessageInterface extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\migrate\Kernel\Plugin\id_map\SqlTest extends \Drupal\Tests\migrate\Kernel\MigrateTestBase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase implements \Drupal\migrate\MigrateMessageInterface extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of SqlTest
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ Plugin/ id_map/ SqlTest.php, line 19
Namespace
Drupal\Tests\migrate\Kernel\Plugin\id_mapView source
class SqlTest extends MigrateTestBase {
/**
* Database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Prophesized event dispatcher.
*
* @var object|\Prophecy\Prophecy\ProphecySubjectInterface|\Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* Definition of a test migration.
*
* @var array
*/
protected $migrationDefinition;
/**
* The migration plugin manager.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManager
*/
protected $migrationPluginManager;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$this->database = \Drupal::database();
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class)
->reveal();
$this->migrationPluginManager = \Drupal::service('plugin.manager.migration');
$this->migrationDefinition = [
'id' => 'test',
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
[
'alpha' => '1',
'bravo' => '2',
'charlie' => '3',
'delta' => '4',
'echo' => '5',
],
],
'ids' => [],
],
'process' => [],
'destination' => [
'plugin' => 'null',
],
];
}
/**
* Tests that ensureTables creates the migrate map table.
*
* @dataProvider providerTestEnsureTables
*/
public function testEnsureTables($ids) {
$this->migrationDefinition['source']['ids'] = $ids;
$migration = $this->migrationPluginManager
->createStubMigration($this->migrationDefinition);
$map = new TestSqlIdMap($this->database, [], 'test', [], $migration, $this->eventDispatcher, $this->migrationPluginManager);
$map->ensureTables();
// Checks that the map table was created.
$exists = $this->database
->schema()
->tableExists('migrate_map_test');
$this->assertTrue($exists);
}
/**
* Provides data for testEnsureTables.
*/
public function providerTestEnsureTables() {
return [
'no ids' => [
[],
],
'one id' => [
[
'alpha' => [
'type' => 'string',
],
],
],
'too many' => [
[
'alpha' => [
'type' => 'string',
],
'bravo' => [
'type' => 'string',
],
'charlie' => [
'type' => 'string',
],
'delta' => [
'type' => 'string',
],
'echo ' => [
'type' => 'string',
],
],
],
];
}
/**
* Tests exception is thrown in ensureTables fails.
*
* @dataProvider providerTestFailEnsureTables
*/
public function testFailEnsureTables($ids) {
// This just tests mysql, as other PDO integrations allow longer indexes.
if (Database::getConnection()->databaseType() !== 'mysql') {
$this->markTestSkipped("This test only runs for MySQL");
}
$this->migrationDefinition['source']['ids'] = $ids;
$migration = $this->container
->get('plugin.manager.migration')
->createStubMigration($this->migrationDefinition);
// Use local id map plugin to force an error.
$map = new SqlIdMapTest($this->database, [], 'test', [], $migration, $this->eventDispatcher, $this->migrationPluginManager);
$this->expectException(DatabaseExceptionWrapper::class);
$this->expectExceptionMessage("Syntax error or access violation: 1074 Column length too big for column 'sourceid1' (max = 16383); use BLOB or TEXT instead:");
$map->ensureTables();
}
/**
* Provides data for testFailEnsureTables.
*/
public function providerTestFailEnsureTables() {
return [
'one id' => [
[
'alpha' => [
'type' => 'string',
],
],
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.