createMock(ServiceInterface::class); $collector = new ServiceCollector(); $collector->addService($service); $contains = false; foreach ($collector->getIterator() as $currentService) { if ($currentService === $service) { $contains = true; break; } } $this->assertTrue($contains); } }