prophesize(MediaRelationRepositoryInterface::class); $repositoryProphecy ->findAll(Argument::that(function (FindAllQuery $query) use ($id) { return $query->getMediaId() == $id; })) ->willReturn($mediaRelationCollection); $service = new MediaRelationService(); $service->setServiceLocator($this->getServiceLocatorMock([ MediaRelationRepositoryInterface::SERVICE_ID => $repositoryProphecy->reveal() ])); $this->assertSame($mediaRelationCollection, $service->getMediaRelations(new FindAllQuery($id))); } }