final class SpyEventDispatcher in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/preprocess_event_dispatcher/tests/src/Unit/Helpers/SpyEventDispatcher.php \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\SpyEventDispatcher
Class SpyEventDispatcher.
Hierarchy
- class \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\SpyEventDispatcher implements \Symfony\Component\EventDispatcher\EventDispatcherInterface
Expanded class hierarchy of SpyEventDispatcher
3 files declare their use of SpyEventDispatcher
- EntityEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ EntityEventTest.php - OtherEventTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ OtherEventTest.php - PreprocessEventPassTest.php in modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ PreprocessEventPassTest.php
File
- modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ Helpers/ SpyEventDispatcher.php, line 16
Namespace
Drupal\Tests\preprocess_event_dispatcher\Unit\HelpersView source
final class SpyEventDispatcher implements EventDispatcherInterface {
/**
* Events keyed by event name.
*
* @var \Symfony\Component\EventDispatcher\Event[]
*/
private $events = [];
/**
* Event count.
*
* @var int
*/
private $count = 1;
/**
* Set the expected event count.
*
* @param int $count
* Event count.
*/
public function setExpectedEventCount(int $count) : void {
$this->count = $count;
}
/**
* Mocking an event dispatch, saving the event.
*
* {@inheritdoc}
*/
public function dispatch($eventName, Event $event = NULL) : void {
if (count($this->events) === $this->count) {
throw new BadMethodCallException("SpyEventDispatcher got called more then {$this->count} time(s)");
}
$this->events[$eventName] = $event;
}
/**
* Get the last event name.
*
* @return string
* Last event name.
*/
public function getLastEventName() : string {
end($this->events);
return key($this->events);
}
/**
* Get the last event.
*
* @return \Symfony\Component\EventDispatcher\Event
* Last event.
*/
public function getLastEvent() : Event {
return end($this->events);
}
/**
* Get the events keyed by event name.
*
* @return \Symfony\Component\EventDispatcher\Event[]
* Events keyed by event name.
*/
public function getEvents() : array {
return $this->events;
}
/**
* Mock.
*
* @inheritdoc
*/
public function addListener($eventName, $listener, $priority = 0) : void {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function addSubscriber(EventSubscriberInterface $subscriber) : void {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function removeListener($eventName, $listener) : void {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function removeSubscriber(EventSubscriberInterface $subscriber) : void {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function getListeners($eventName = NULL) : array {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function getListenerPriority($eventName, $listener) : ?int {
throw new BadMethodCallException('This spy does not support this call');
}
/**
* Mock.
*
* @inheritdoc
*/
public function hasListeners($eventName = NULL) : bool {
throw new BadMethodCallException('This spy does not support this call');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SpyEventDispatcher:: |
private | property | Event count. | |
SpyEventDispatcher:: |
private | property | Events keyed by event name. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mocking an event dispatch, saving the event. | |
SpyEventDispatcher:: |
public | function | Get the events keyed by event name. | |
SpyEventDispatcher:: |
public | function | Get the last event. | |
SpyEventDispatcher:: |
public | function | Get the last event name. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Mock. | |
SpyEventDispatcher:: |
public | function | Set the expected event count. |