1212
1313namespace CloudCreativity \Modules \Testing ;
1414
15+ use ArrayAccess ;
1516use CloudCreativity \Modules \Contracts \Application \Ports \Driven \OutboundEventPublisher ;
1617use CloudCreativity \Modules \Contracts \Toolkit \Messages \IntegrationEvent ;
1718use Countable ;
19+ use Generator ;
20+ use IteratorAggregate ;
1821use LogicException ;
1922
20- class FakeOutboundEventPublisher implements OutboundEventPublisher, Countable
23+ /**
24+ * @implements ArrayAccess<int, IntegrationEvent>
25+ * @implements IteratorAggregate<int, IntegrationEvent>
26+ */
27+ class FakeOutboundEventPublisher implements OutboundEventPublisher, Countable, ArrayAccess, IteratorAggregate
2128{
2229 /**
2330 * @var list<IntegrationEvent>
@@ -29,6 +36,34 @@ public function publish(IntegrationEvent $event): void
2936 $ this ->events [] = $ event ;
3037 }
3138
39+ public function offsetExists (mixed $ offset ): bool
40+ {
41+ return isset ($ this ->events [$ offset ]);
42+ }
43+
44+ public function offsetGet (mixed $ offset ): IntegrationEvent
45+ {
46+ return $ this ->events [$ offset ];
47+ }
48+
49+ public function offsetSet (mixed $ offset , mixed $ value ): void
50+ {
51+ throw new LogicException ('Cannot set integration events. ' );
52+ }
53+
54+ public function offsetUnset (mixed $ offset ): void
55+ {
56+ throw new LogicException ('Cannot unset integration events. ' );
57+ }
58+
59+ /**
60+ * @return Generator<int, IntegrationEvent>
61+ */
62+ public function getIterator (): Generator
63+ {
64+ yield from $ this ->events ;
65+ }
66+
3267 public function count (): int
3368 {
3469 return count ($ this ->events );
0 commit comments