You are here

protected function StubTestTrait::createEntityStub in Drupal 9

Same name and namespace in other branches
  1. 8 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.

2 calls to StubTestTrait::createEntityStub()
MigrateBlockContentStubTest::testStubFailure in core/modules/block_content/tests/src/Kernel/Migrate/MigrateBlockContentStubTest.php
Tests creation of block content stubs with no block_content_type available.
StubTestTrait::performStubTest in core/modules/migrate_drupal/src/Tests/StubTestTrait.php
Tests that a stub of the given entity type results in a valid 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);
}