You are here

protected function MigrateTableTest::setUp in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/MigrateTableTest.php \Drupal\Tests\migrate_plus\Kernel\MigrateTableTest::setUp()
  2. 8.4 tests/src/Kernel/MigrateTableTest.php \Drupal\Tests\migrate_plus\Kernel\MigrateTableTest::setUp()

Overrides MigrateTestBase::setUp

File

tests/src/Kernel/MigrateTableTest.php, line 42

Class

MigrateTableTest
Tests migration destination table.

Namespace

Drupal\Tests\migrate_plus\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this->connection = $this->container
    ->get('database');
  $connections = [
    static::SOURCE_TABLE_NAME => $this->sourceDatabase,
    static::DEST_TABLE_NAME => $this->connection,
  ];
  foreach ($connections as $table => $connection) {
    $connection
      ->schema()
      ->createTable($table, [
      'description' => 'Test table',
      'fields' => [
        'data' => [
          'type' => 'varchar',
          'length' => '32',
          'not null' => TRUE,
        ],
        'data2' => [
          'type' => 'varchar',
          'length' => '32',
          'not null' => TRUE,
        ],
        'data3' => [
          'type' => 'varchar',
          'length' => '32',
          'not null' => TRUE,
        ],
      ],
      'primary key' => [
        'data',
      ],
    ]);
  }
  $query = $this->sourceDatabase
    ->insert(static::SOURCE_TABLE_NAME)
    ->fields([
    'data',
    'data2',
    'data3',
  ]);
  $values = [
    [
      'data' => 'dummy value',
      'data2' => 'dummy2 value',
      'data3' => 'dummy3 value',
    ],
    [
      'data' => 'dummy value2',
      'data2' => 'dummy2 value2',
      'data3' => 'dummy3 value2',
    ],
    [
      'data' => 'dummy value3',
      'data2' => 'dummy2 value3',
      'data3' => 'dummy3 value3',
    ],
  ];
  foreach ($values as $record) {
    $query
      ->values($record);
  }
  $query
    ->execute();
}