dispatchMethodCallCounter; Assert::assertInstanceOf(ObjectCollectEvent::class, $event); return new ObjectCollection(); } }; $objectCollector = new ObjectCollector($dispatcher); $objectCollection = $objectCollector->getObjects(); // Calling for the second time to ensure it's cached and the dispatcher is called only once. $objectCollection = $objectCollector->getObjects(); Assert::assertInstanceOf(ObjectCollection::class, $objectCollection); Assert::assertEquals(1, $dispatcher->dispatchMethodCallCounter); } }