You are here

public function EntityTypeBaseFieldTest::testEntityBaseFieldInfoEvent in Hook Event Dispatcher 8

Test the EntityBaseFieldInfoEvent.

File

tests/src/Unit/EntityType/EntityTypeBaseFieldTest.php, line 42

Class

EntityTypeBaseFieldTest
Class EntityTypeTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\EntityType

Code

public function testEntityBaseFieldInfoEvent() {
  $fields = [
    'field_test1' => 'test',
    'field_test2' => 'otherTest',
  ];
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::ENTITY_BASE_FIELD_INFO => function (EntityBaseFieldInfoEvent $event) use ($fields) {
      $event
        ->setFields($fields);
    },
  ]);
  $entityType = $this
    ->createMock(EntityTypeInterface::class);
  $hookFieldInfoResult = hook_event_dispatcher_entity_base_field_info($entityType);

  /** @var \Drupal\hook_event_dispatcher\Event\EntityType\EntityBaseFieldInfoEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_BASE_FIELD_INFO);
  self::assertEquals($entityType, $event
    ->getEntityType());
  self::assertEquals($fields, $event
    ->getFields());
  self::assertEquals($fields, $hookFieldInfoResult);
}