Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
RecordingDispatcher
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 dispatch
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 of
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Testing;
6
7use Psr\EventDispatcher\EventDispatcherInterface;
8
9final class RecordingDispatcher implements EventDispatcherInterface
10{
11    /** @var list<object> */
12    public array $events = [];
13
14    public function dispatch(object $event): object
15    {
16        $this->events[] = $event;
17
18        return $event;
19    }
20
21    /**
22     * @template T of object
23     * @param class-string<T> $class
24     * @return list<T>
25     */
26    public function of(string $class): array
27    {
28        return array_values(array_filter($this->events, static fn(object $e): bool => $e instanceof $class));
29    }
30}