function StubTestTrait::createEntityStub

Same name and namespace in other branches
  1. 11.x core/modules/migrate_drupal/src/Tests/StubTestTrait.php \Drupal\migrate_drupal\Tests\StubTestTrait::createEntityStub()

Create a stub of the given entity type.

Parameters

string $entity_type_id: The entity type we are stubbing.

Return value

int ID of the created entity.

File

core/modules/migrate_drupal/src/Tests/StubTestTrait.php, line 34

Class

StubTestTrait
Provides common functionality for testing stubbing.

Namespace

Drupal\migrate_drupal\Tests

Code

protected function createEntityStub($entity_type_id) {
  // Create a dummy migration to pass to the destination plugin.
  $definition = [
    'migration_tags' => [
      'Stub test',
    ],
    'source' => [
      'plugin' => 'empty',
    ],
    'process' => [],
    'destination' => [
      'plugin' => 'entity:' . $entity_type_id,
    ],
  ];
  $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
  $destination_plugin = $migration->getDestinationPlugin(TRUE);
  $stub_row = new Row([], [], TRUE);
  $destination_ids = $destination_plugin->import($stub_row);
  return reset($destination_ids);
}

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