dispatchMethodCallCounter; \assert($event instanceof FieldCollectEvent); Assert::assertSame('contact', $event->getObject()); return new FieldCollection(); } }; $fieldCollector = new FieldCollector($dispatcher); $fieldCollection = $fieldCollector->getFields('contact'); // Calling for the second time to ensure it's cached and the dispatcher is called only once. $fieldCollection = $fieldCollector->getFields('contact'); Assert::assertInstanceOf(FieldCollection::class, $fieldCollection); Assert::assertEquals(1, $dispatcher->dispatchMethodCallCounter); } }