class HookEventDispatcherManagerSpy in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 tests/src/Unit/HookEventDispatcherManagerSpy.php \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
- 8 tests/src/Unit/HookEventDispatcherManagerSpy.php \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
Class HookEventDispatcherManagerSpy.
@package Drupal\Tests\hook_event_dispatcher\Unit
Hierarchy
- class \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy implements HookEventDispatcherManagerInterface
Expanded class hierarchy of HookEventDispatcherManagerSpy
39 files declare their use of HookEventDispatcherManagerSpy
- AbstractFieldSettingsSummaryAlterEventTestCase.php in modules/
field_event_dispatcher/ tests/ src/ Unit/ Field/ AbstractFieldSettingsSummaryAlterEventTestCase.php - AbstractFormEntityDisplayEditAlterEventSubscriberTestCase.php in modules/
field_event_dispatcher/ tests/ src/ Unit/ Field/ AbstractFormEntityDisplayEditAlterEventSubscriberTestCase.php - BlockEventTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Block/ BlockEventTest.php - CronEventTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Core/ CronEventTest.php - EntityAccessEventTest.php in modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityAccessEventTest.php
File
- tests/
src/ Unit/ HookEventDispatcherManagerSpy.php, line 15
Namespace
Drupal\Tests\hook_event_dispatcher\UnitView source
class HookEventDispatcherManagerSpy implements HookEventDispatcherManagerInterface {
/**
* The maximum amount of events that should register.
*
* @var int
*/
private $maxEventCount = 1;
/**
* Event callbacks.
*
* @var array
*/
private $eventCallbacks = [];
/**
* The amount of event registered.
*
* @var int
*/
private $eventCount = 0;
/**
* Registered events.
*
* @var \Drupal\hook_event_dispatcher\Event\EventInterface[]
*/
private $registeredEvents = [];
/**
* {@inheritdoc}
*
* @throws \Drupal\Tests\hook_event_dispatcher\Unit\TooManyEventsException
*/
public function register(EventInterface $event) : Event {
$this->eventCount++;
if ($this->eventCount > $this->maxEventCount) {
throw new TooManyEventsException("Got {$this->eventCount} events, but only {$this->maxEventCount} are allowed");
}
$type = $event
->getDispatcherType();
$this->registeredEvents[$type] = $event;
if (isset($this->eventCallbacks[$type])) {
$this->eventCallbacks[$type]($event);
}
return $event;
}
/**
* Set max event count.
*
* @param int $maxEventCount
* Event count.
*/
public function setMaxEventCount($maxEventCount) : void {
$this->maxEventCount = $maxEventCount;
}
/**
* Set event callbacks.
*
* @param array $eventCallbacks
* Associative event callbacks array.
*/
public function setEventCallbacks(array $eventCallbacks) : void {
$this->eventCallbacks = $eventCallbacks;
}
/**
* Getter.
*
* @param string $eventName
* Event name.
*
* @return \Drupal\hook_event_dispatcher\Event\EventInterface
* Registered event by name.
*
* @throws \InvalidArgumentException
*/
public function getRegisteredEvent($eventName) : EventInterface {
if (!isset($this->registeredEvents[$eventName])) {
throw new InvalidArgumentException("The event '{$eventName}' was not registered");
}
return $this->registeredEvents[$eventName];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HookEventDispatcherManagerSpy:: |
private | property | Event callbacks. | |
HookEventDispatcherManagerSpy:: |
private | property | The amount of event registered. | |
HookEventDispatcherManagerSpy:: |
private | property | The maximum amount of events that should register. | |
HookEventDispatcherManagerSpy:: |
private | property | Registered events. | |
HookEventDispatcherManagerSpy:: |
public | function | Getter. | |
HookEventDispatcherManagerSpy:: |
public | function |
Overrides HookEventDispatcherManagerInterface:: |
|
HookEventDispatcherManagerSpy:: |
public | function | Set event callbacks. | |
HookEventDispatcherManagerSpy:: |
public | function | Set max event count. |