function MigrateEntityContentBaseTest::testBundleFallbackForStub

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testBundleFallbackForStub()
  2. 10 core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php \Drupal\Tests\migrate\Kernel\MigrateEntityContentBaseTest::testBundleFallbackForStub()

Tests bundle is properly provided for stubs without bundle support.

@todo Remove this test in when native PHP type-hints will be added for EntityFieldManagerInterface::getFieldDefinitions(). See https://www.drupal.org/project/drupal/issues/3050720.

File

core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php, line 318

Class

MigrateEntityContentBaseTest
Tests the EntityContentBase destination.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testBundleFallbackForStub() : void {
    $this->enableModules([
        'migrate_entity_test',
    ]);
    $this->installEntitySchema('migrate_string_id_entity_test');
    $entity_type_manager = $this->container
        ->get('entity_type.manager');
    $entity_type_bundle_info = $this->container
        ->get('entity_type.bundle.info');
    $entity_display_repository = $this->container
        ->get('entity_display.repository');
    $typed_data_manager = $this->container
        ->get('typed_data_manager');
    $language_manager = $this->container
        ->get('language_manager');
    $keyvalue = $this->container
        ->get('keyvalue');
    $module_handler = $this->container
        ->get('module_handler');
    $cache_discovery = $this->container
        ->get('cache.discovery');
    $entity_last_installed_schema_repository = $this->container
        ->get('entity.last_installed_schema.repository');
    $decorated_entity_field_manager = new class ($entity_type_manager, $entity_type_bundle_info, $entity_display_repository, $typed_data_manager, $language_manager, $keyvalue, $module_handler, $cache_discovery, $entity_last_installed_schema_repository) extends EntityFieldManager {
        
        /**
         * {@inheritdoc}
         */
        public function getFieldDefinitions($entity_type_id, $bundle) {
            if (\is_null($bundle)) {
                throw new \Exception("Bundle value shouldn't be NULL.");
            }
            return parent::getFieldDefinitions($entity_type_id, $bundle);
        }

};
    $this->container
        ->set('entity_field.manager', $decorated_entity_field_manager);
    $this->createEntityStub('migrate_string_id_entity_test');
}

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