function StubTestTrait::createEntityStub

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/src/Tests/StubTestTrait.php \Drupal\migrate_drupal\Tests\StubTestTrait::createEntityStub()
  2. 10 core/modules/migrate_drupal/src/Tests/StubTestTrait.php \Drupal\migrate_drupal\Tests\StubTestTrait::createEntityStub()
  3. 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.

3 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.
MigrateEntityContentBaseTest::testBundleFallbackForStub in core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php
Tests bundle is properly provided for stubs without bundle support.
StubTestTrait::performStubTest in core/modules/migrate_drupal/src/Tests/StubTestTrait.php
Tests that creating a stub of an 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);
}

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