class EventFake implements Fake, Dispatcher

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.

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 never
throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

string
firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

array
firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

array
closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

array
closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

__construct(Dispatcher $dispatcher, array|string $eventsToFake = [])

Create a new event fake instance.

except(array|string $eventsToDispatch)

Specify the events that should be dispatched instead of faked.

void
assertListening(string $expectedEvent, array|string $expectedListener)

Assert if an event has a listener attached to it.

void
assertDispatched(Closure|string $event, callable|int|null $callback = null)

Assert if an event was dispatched based on a truth-test callback.

void
assertDispatchedOnce(string $event)

Assert if an event was dispatched exactly once.

void
assertDispatchedTimes(string $event, int $times = 1)

Assert if an event was dispatched a number of times.

void
assertNotDispatched(Closure|string $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.

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(array|Closure|QueuedClosure|string $events, array|object|string|null $listener = null)

Register an event listener with the dispatcher.

void
observe(array|string $events, array|object|string $observer)

Register a passive event observer with the dispatcher.

bool
hasListeners(string $eventName)

Determine if a given event has listeners.

void
push(string $event, mixed $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.

mixed
dispatch(object|string $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.

void
fakeEvent(object|string $event, string $name, array $arguments)

Push the event onto the fake events array immediately or after the next database transaction.

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 events queued via push() in the current coroutine.

mixed
until(object|string $event, mixed $payload = [])

Dispatch an event and call the listeners.

array
dispatchedEvents()

Get the events that have been dispatched.

mixed
__call(string $method, array $parameters)

Handle dynamic method calls to the dispatcher.

Details

in ForwardsCalls at line 22
protected mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 52
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.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 66
static protected never throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

never

Exceptions

BadMethodCallException

in ReflectsClosures at line 25
protected string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

Parameters

Closure $closure

Return Value

string

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 48
protected array firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 74
protected array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

in ReflectsClosures at line 94
protected array closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

at line 49
__construct(Dispatcher $dispatcher, array|string $eventsToFake = [])

Create a new event fake instance.

Parameters

Dispatcher $dispatcher
array|string $eventsToFake

at line 59
EventFake except(array|string $eventsToDispatch)

Specify the events that should be dispatched instead of faked.

Parameters

array|string $eventsToDispatch

Return Value

EventFake

at line 72
void assertListening(string $expectedEvent, array|string $expectedListener)

Assert if an event has a listener attached to it.

Parameters

string $expectedEvent
array|string $expectedListener

Return Value

void

at line 117
void assertDispatched(Closure|string $event, callable|int|null $callback = null)

Assert if an event was dispatched based on a truth-test callback.

Parameters

Closure|string $event
callable|int|null $callback

Return Value

void

at line 137
void assertDispatchedOnce(string $event)

Assert if an event was dispatched exactly once.

Parameters

string $event

Return Value

void

at line 145
void assertDispatchedTimes(string $event, int $times = 1)

Assert if an event was dispatched a number of times.

Parameters

string $event
int $times

Return Value

void

at line 163
void assertNotDispatched(Closure|string $event, callable|null $callback = null)

Determine if an event was dispatched based on a truth-test callback.

Parameters

Closure|string $event
callable|null $callback

Return Value

void

at line 179
void assertNothingDispatched()

Assert that no events were dispatched.

Return Value

void

at line 202
Collection dispatched(string $event, callable|null $callback = null)

Get all of the events matching a truth-test callback.

Parameters

string $event
callable|null $callback

Return Value

Collection

at line 220
bool hasDispatched(string $event)

Determine if the given event has been dispatched.

Parameters

string $event

Return Value

bool

at line 228
void listen(array|Closure|QueuedClosure|string $events, array|object|string|null $listener = null)

Register an event listener with the dispatcher.

Parameters

array|Closure|QueuedClosure|string $events
array|object|string|null $listener

Return Value

void

at line 238
void observe(array|string $events, array|object|string $observer)

Register a passive event observer with the dispatcher.

Parameters

array|string $events
array|object|string $observer

Return Value

void

at line 246
bool hasListeners(string $eventName)

Determine if a given event has listeners.

Parameters

string $eventName

Return Value

bool

at line 282
void push(string $event, mixed $payload = [])

Register an event and payload to be dispatched later.

Parameters

string $event
mixed $payload

Return Value

void

at line 289
void subscribe(object|string $subscriber)

Register an event subscriber with the dispatcher.

Parameters

object|string $subscriber

Return Value

void

at line 297
void flush(string $event)

Flush a set of pushed events.

Parameters

string $event

Return Value

void

at line 304
mixed dispatch(object|string $event, mixed $payload = [], bool $halt = false)

Fire an event and call the listeners.

Parameters

object|string $event
mixed $payload
bool $halt

Return Value

mixed

at line 320
protected bool shouldFakeEvent(string $eventName, mixed $payload)

Determine if an event should be faked or actually dispatched.

Parameters

string $eventName
mixed $payload

Return Value

bool

at line 342
protected void fakeEvent(object|string $event, string $name, array $arguments)

Push the event onto the fake events array immediately or after the next database transaction.

Parameters

object|string $event
string $name
array $arguments

Return Value

void

at line 357
protected bool shouldDispatchEvent(string $eventName, mixed $payload)

Determine whether an event should be dispatched or not.

Parameters

string $eventName
mixed $payload

Return Value

bool

at line 375
void forget(string $event)

Remove a set of listeners from the dispatcher.

Parameters

string $event

Return Value

void

at line 382
void forgetPushed()

Forget all events queued via push() in the current coroutine.

Return Value

void

at line 389
mixed until(object|string $event, mixed $payload = [])

Dispatch an event and call the listeners.

Parameters

object|string $event
mixed $payload

Return Value

mixed

at line 397
array dispatchedEvents()

Get the events that have been dispatched.

Return Value

array

at line 405
mixed __call(string $method, array $parameters)

Handle dynamic method calls to the dispatcher.

Parameters

string $method
array $parameters

Return Value

mixed