class FieldStorageCreateCheckDeprecationTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Field/FieldStorageCreateCheckDeprecationTest.php \Drupal\KernelTests\Core\Field\FieldStorageCreateCheckDeprecationTest

Tests the field storage create check subscriber.

Attributes

#[Group('Field')] #[IgnoreDeprecations] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of FieldStorageCreateCheckDeprecationTest

File

core/tests/Drupal/KernelTests/Core/Field/FieldStorageCreateCheckDeprecationTest.php, line 19

Namespace

Drupal\KernelTests\Core\Field
View source
class FieldStorageCreateCheckDeprecationTest extends KernelTestBase {
  
  /**
   * Modules to load.
   *
   * @var array
   */
  protected static $modules = [
    'entity_test',
    'field',
    'user',
  ];
  
  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) : void {
    parent::register($container);
    // Change the service to act like this is a non-core test.
    $container->register('testing.field_storage_create_check', FieldStorageCreateCheckSubscriber::class)
      ->addArgument(new Reference('database'))
      ->addArgument(new Reference('entity_type.manager'))
      ->addArgument(FALSE)
      ->addTag('event_subscriber');
  }
  
  /**
   * Tests the field storage create check subscriber.
   */
  public function testFieldStorageCreateCheck() : void {
    $this->expectDeprecation('Creating the "entity_test.field_test" field storage definition without the entity schema "entity_test" being installed is deprecated in drupal:11.2.0 and will be replaced by a LogicException in drupal:12.0.0. See https://www.drupal.org/node/3493981');
    FieldStorageConfig::create([
      'field_name' => 'field_test',
      'entity_type' => 'entity_test',
      'type' => 'integer',
    ])->save();
  }

}

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