getServiceLocatorMock([ DeliveryAssemblyService::class => $this->getDeliveryAssemblyServiceMock() ]); $service->setServiceLocator($serviceLocator); $result = $service->deleteDeliveryData($request); $this->assertTrue($result); } private function getDeliveryAssemblyServiceMock() { $service = $this->getMockBuilder(DeliveryAssemblyService::class)->getMock(); $service->method('deleteInstance') ->willReturn(true); return $service; } }