You are here

public function MigrateSqlIdMapEnsureTablesTest::testEnsureTablesExist in Drupal 8

Tests the ensureTables method when the tables exist.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php, line 138

Class

MigrateSqlIdMapEnsureTablesTest
Tests the SQL ID map plugin ensureTables() method.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testEnsureTablesExist() {
  $schema = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Schema')
    ->disableOriginalConstructor()
    ->getMock();
  $schema
    ->expects($this
    ->at(0))
    ->method('tableExists')
    ->with('migrate_map_sql_idmap_test')
    ->will($this
    ->returnValue(TRUE));
  $schema
    ->expects($this
    ->at(1))
    ->method('fieldExists')
    ->with('migrate_map_sql_idmap_test', 'rollback_action')
    ->will($this
    ->returnValue(FALSE));
  $field_schema = [
    'type' => 'int',
    'size' => 'tiny',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag indicating what to do for this item on rollback',
  ];
  $schema
    ->expects($this
    ->at(2))
    ->method('addField')
    ->with('migrate_map_sql_idmap_test', 'rollback_action', $field_schema);
  $schema
    ->expects($this
    ->at(3))
    ->method('fieldExists')
    ->with('migrate_map_sql_idmap_test', 'hash')
    ->will($this
    ->returnValue(FALSE));
  $field_schema = [
    'type' => 'varchar',
    'length' => '64',
    'not null' => FALSE,
    'description' => 'Hash of source row data, for detecting changes',
  ];
  $schema
    ->expects($this
    ->at(4))
    ->method('addField')
    ->with('migrate_map_sql_idmap_test', 'hash', $field_schema);
  $schema
    ->expects($this
    ->at(5))
    ->method('fieldExists')
    ->with('migrate_map_sql_idmap_test', 'source_ids_hash')
    ->will($this
    ->returnValue(FALSE));
  $field_schema = [
    'type' => 'varchar',
    'length' => '64',
    'not null' => TRUE,
    'description' => 'Hash of source ids. Used as primary key',
  ];
  $schema
    ->expects($this
    ->at(6))
    ->method('addField')
    ->with('migrate_map_sql_idmap_test', 'source_ids_hash', $field_schema);
  $schema
    ->expects($this
    ->exactly(7))
    ->method($this
    ->anything());
  $this
    ->runEnsureTablesTest($schema);
}