function SqlBaseTest::testPrepareQuery

Tests prepare query method.

File

core/modules/migrate/tests/src/Kernel/SqlBaseTest.php, line 206

Class

SqlBaseTest
Tests the functionality of SqlBase.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testPrepareQuery() : void {
    $this->prepareSourceData();
    $this->enableModules([
        'migrate_sql_prepare_query_test',
        'entity_test',
    ]);
    
    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->container
        ->get('plugin.manager.migration')
        ->createStubMigration([
        'source' => [
            'plugin' => 'test_sql_prepare_query',
        ],
        'process' => [
            'id' => 'id',
            'name' => 'name',
        ],
        'destination' => [
            'plugin' => 'entity:entity_test',
        ],
    ]);
    // One item is excluded by the condition defined in the source plugin.
    // @see \Drupal\migrate_sql_prepare_query_test\Plugin\migrate\source\TestSqlPrepareQuery
    $count = $migration->getSourcePlugin()
        ->count();
    $this->assertEquals(2, $count);
    // Run the migration and verify that the number of migrated items matches
    // the initial source count.
    (new MigrateExecutable($migration, new MigrateMessage()))->import();
    $this->assertEquals(2, $migration->getIdMap()
        ->processedCount());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.