public function UserEventTest::testUserFormatNameAlterEventByReference in Hook Event Dispatcher 8
User format name alter event by reference test.
File
- tests/
src/ Unit/ User/ UserEventTest.php, line 128
Class
- UserEventTest
- Class UserEventTest.
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\UserCode
public function testUserFormatNameAlterEventByReference() {
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::USER_FORMAT_NAME_ALTER => function (UserFormatNameAlterEvent $event) {
$name =& $event
->getName();
$name .= ' improved!';
},
]);
$name = 'Test name';
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $this
->createMock(AccountInterface::class);
hook_event_dispatcher_user_format_name_alter($name, $account);
/** @var \Drupal\hook_event_dispatcher\Event\User\UserFormatNameAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::USER_FORMAT_NAME_ALTER);
self::assertSame('Test name improved!', $event
->getName());
self::assertSame($account, $event
->getAccount());
}