Loading src/Plugin/migrate/source/Table.php +11 −0 Changes for src/Plugin/migrate/source/Table.php: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\migrate_plus\Plugin\migrate\source; use Drupal\Core\State\StateInterface; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Plugin\MigrationInterface; Loading Loading @@ -141,4 +142,14 @@ class Table extends SqlBase { return $this->idFields; } /** * {@inheritdoc} */ public function checkRequirements() { if (!$this->getDatabase()->schema()->tableExists($this->tableName)) { throw new RequirementsException("Source database table '{$this->tableName}' does not exist", ['source_table' => $this->tableName]); } parent::checkRequirements(); } } tests/src/Kernel/Plugin/migrate/source/TableTest.php 0 → 100644 +70 −0 Changes for tests/src/Kernel/Plugin/migrate/source/TableTest.php: 70 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\source; use Drupal\migrate\Exception\RequirementsException; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** * Tests Table source plugin. * * @covers \Drupal\migrate_plus\Plugin\migrate\source\Table * * @group migrate_plus */ class TableTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} */ protected static $modules = ['migrate_plus']; /** * The migration plugin manager. * * @var \Drupal\migrate\Plugin\MigrationPluginManager */ protected $migrationPluginManager; /** * Definition of a test migration. * * @var array */ protected $migrationDefinition; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->migrationPluginManager = \Drupal::service('plugin.manager.migration'); $this->migrationDefinition = [ 'id' => 'test', 'source' => [ 'plugin' => 'table', 'table_name' => 'foo', 'fields' => [], 'id_fields' => [], ], 'process' => [], 'destination' => [ 'plugin' => 'null', ], ]; } /** * Tests 'Table' source plugin requirements. */ public function testCheckRequirements() { $this->expectException(RequirementsException::class); $this->expectExceptionMessage("Source database table 'foo' does not exist"); $this->migrationPluginManager->createStubMigration($this->migrationDefinition) ->getSourcePlugin() ->checkRequirements(); } } Loading
src/Plugin/migrate/source/Table.php +11 −0 Changes for src/Plugin/migrate/source/Table.php: 11 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\migrate_plus\Plugin\migrate\source; use Drupal\Core\State\StateInterface; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Plugin\MigrationInterface; Loading Loading @@ -141,4 +142,14 @@ class Table extends SqlBase { return $this->idFields; } /** * {@inheritdoc} */ public function checkRequirements() { if (!$this->getDatabase()->schema()->tableExists($this->tableName)) { throw new RequirementsException("Source database table '{$this->tableName}' does not exist", ['source_table' => $this->tableName]); } parent::checkRequirements(); } }
tests/src/Kernel/Plugin/migrate/source/TableTest.php 0 → 100644 +70 −0 Changes for tests/src/Kernel/Plugin/migrate/source/TableTest.php: 70 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\source; use Drupal\migrate\Exception\RequirementsException; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** * Tests Table source plugin. * * @covers \Drupal\migrate_plus\Plugin\migrate\source\Table * * @group migrate_plus */ class TableTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} */ protected static $modules = ['migrate_plus']; /** * The migration plugin manager. * * @var \Drupal\migrate\Plugin\MigrationPluginManager */ protected $migrationPluginManager; /** * Definition of a test migration. * * @var array */ protected $migrationDefinition; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->migrationPluginManager = \Drupal::service('plugin.manager.migration'); $this->migrationDefinition = [ 'id' => 'test', 'source' => [ 'plugin' => 'table', 'table_name' => 'foo', 'fields' => [], 'id_fields' => [], ], 'process' => [], 'destination' => [ 'plugin' => 'null', ], ]; } /** * Tests 'Table' source plugin requirements. */ public function testCheckRequirements() { $this->expectException(RequirementsException::class); $this->expectExceptionMessage("Source database table 'foo' does not exist"); $this->migrationPluginManager->createStubMigration($this->migrationDefinition) ->getSourcePlugin() ->checkRequirements(); } }