You are here

public function UserEventTest::testUserCancelMethodsAlterEventByReference in Hook Event Dispatcher 8

User cancel methods alter event by reference test.

File

tests/src/Unit/User/UserEventTest.php, line 61

Class

UserEventTest
Class UserEventTest.

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\User

Code

public function testUserCancelMethodsAlterEventByReference() {
  $this->manager
    ->setEventCallbacks([
    HookEventDispatcherInterface::USER_CANCEL_METHODS_ALTER => function (UserCancelMethodsAlterEvent $event) {
      $name =& $event
        ->getMethods()[0];
      $name .= ' improved!';
    },
  ]);
  $methods = [
    'Test method',
  ];
  hook_event_dispatcher_user_cancel_methods_alter($methods);

  /** @var \Drupal\hook_event_dispatcher\Event\User\UserCancelMethodsAlterEvent $event */
  $event = $this->manager
    ->getRegisteredEvent(HookEventDispatcherInterface::USER_CANCEL_METHODS_ALTER);
  self::assertSame([
    'Test method improved!',
  ], $event
    ->getMethods());
}