On this page
EventFake
class EventFake implements Dispatcher, Fake (View source)
Traits
Properties
Dispatcher | $dispatcher | The original event dispatcher. |
|
protected array | $eventsToFake | The event types that should be intercepted instead of dispatched. |
|
protected array | $eventsToDispatch | The event types that should be dispatched instead of intercepted. |
|
protected array | $events | All of the events that have been intercepted keyed by type. |
Methods
mixed | forwardCallTo(mixed $object, string $method, array $parameters) Forward a method call to the given object. |
from ForwardsCalls |
mixed | forwardDecoratedCallTo(mixed $object, string $method, array $parameters) Forward a method call to the given object, returning $this if the forwarded call returned itself. |
from ForwardsCalls |
static void | throwBadMethodCallException(string $method) Throw a bad method call exception for the given method. |
from ForwardsCalls |
string | firstClosureParameterType(Closure $closure) Get the class name of the first parameter of the given Closure. |
from ReflectsClosures |
array | firstClosureParameterTypes(Closure $closure) Get the class names of the first parameter of the given Closure, including union types. |
from ReflectsClosures |
array | closureParameterTypes(Closure $closure) Get the class names / types of the parameters of the given Closure. |
from ReflectsClosures |
void | __construct(Dispatcher $dispatcher, array|string $eventsToFake = []) Create a new event fake instance. |
|
$this | except(array|string $eventsToDispatch) Specify the events that should be dispatched instead of faked. |
|
void | assertListening(string $expectedEvent, string|array $expectedListener) Assert if an event has a listener attached to it. |
|
void | assertDispatched(string|Closure $event, callable|int|null $callback = null) Assert if an event was dispatched based on a truth-test callback. |
|
void | assertDispatchedTimes(string $event, int $times = 1) Assert if an event was dispatched a number of times. |
|
void | assertNotDispatched(string|Closure $event, callable|null $callback = null) Determine if an event was dispatched based on a truth-test callback. |
|
void | assertNothingDispatched() Assert that no events were dispatched. |
|
Collection | dispatched(string $event, callable|null $callback = null) Get all of the events matching a truth-test callback. |
|
bool | hasDispatched(string $event) Determine if the given event has been dispatched. |
|
void | listen(Closure|string|array $events, Closure|string|array|null $listener = null) Register an event listener with the dispatcher. |
|
bool | hasListeners(string $eventName) Determine if a given event has listeners. |
|
void | push(string $event, array $payload = []) Register an event and payload to be dispatched later. |
|
void | subscribe(object|string $subscriber) Register an event subscriber with the dispatcher. |
|
void | flush(string $event) Flush a set of pushed events. |
|
array|null | dispatch(string|object $event, mixed $payload = [], bool $halt = false) Fire an event and call the listeners. |
|
bool | shouldFakeEvent(string $eventName, mixed $payload) Determine if an event should be faked or actually dispatched. |
|
bool | shouldDispatchEvent(string $eventName, mixed $payload) Determine whether an event should be dispatched or not. |
|
void | forget(string $event) Remove a set of listeners from the dispatcher. |
|
void | forgetPushed() Forget all of the queued listeners. |
|
array|null | until(string|object $event, mixed $payload = []) Dispatch an event and call the listeners. |
|
mixed | __call(string $method, array $parameters) Handle dynamic method calls to the dispatcher. |
Details
protected mixed forwardCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object.
protected mixed forwardDecoratedCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object, returning $this if the forwarded call returned itself.
static protected void throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
protected string firstClosureParameterType(Closure $closure)
Get the class name of the first parameter of the given Closure.
protected array firstClosureParameterTypes(Closure $closure)
Get the class names of the first parameter of the given Closure, including union types.
protected array closureParameterTypes(Closure $closure)
Get the class names / types of the parameters of the given Closure.
void __construct(Dispatcher $dispatcher, array|string $eventsToFake = [])
Create a new event fake instance.
$this except(array|string $eventsToDispatch)
Specify the events that should be dispatched instead of faked.
void assertListening(string $expectedEvent, string|array $expectedListener)
Assert if an event has a listener attached to it.
void assertDispatched(string|Closure $event, callable|int|null $callback = null)
Assert if an event was dispatched based on a truth-test callback.
void assertDispatchedTimes(string $event, int $times = 1)
Assert if an event was dispatched a number of times.
void assertNotDispatched(string|Closure $event, callable|null $callback = null)
Determine if an event was dispatched based on a truth-test callback.
void assertNothingDispatched()
Assert that no events were dispatched.
Collection dispatched(string $event, callable|null $callback = null)
Get all of the events matching a truth-test callback.
bool hasDispatched(string $event)
Determine if the given event has been dispatched.
void listen(Closure|string|array $events, Closure|string|array|null $listener = null)
Register an event listener with the dispatcher.
bool hasListeners(string $eventName)
Determine if a given event has listeners.
void push(string $event, array $payload = [])
Register an event and payload to be dispatched later.
void subscribe(object|string $subscriber)
Register an event subscriber with the dispatcher.
void flush(string $event)
Flush a set of pushed events.
array|null dispatch(string|object $event, mixed $payload = [], bool $halt = false)
Fire an event and call the listeners.
protected bool shouldFakeEvent(string $eventName, mixed $payload)
Determine if an event should be faked or actually dispatched.
protected bool shouldDispatchEvent(string $eventName, mixed $payload)
Determine whether an event should be dispatched or not.
void forget(string $event)
Remove a set of listeners from the dispatcher.
void forgetPushed()
Forget all of the queued listeners.
array|null until(string|object $event, mixed $payload = [])
Dispatch an event and call the listeners.
mixed __call(string $method, array $parameters)
Handle dynamic method calls to the dispatcher.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Support/Testing/Fakes/EventFake.html