createMock(SearchProxy::class); $searchServiceMock->expects($this->once()) ->method('searchByQuery') ->with($query) ->willReturn(['data' => [['id' => $testId]]]); $serviceLocator = $this->getServiceLocatorMock([SearchProxy::SERVICE_ID => $searchServiceMock]); $generisUserServiceMock = $this->getMockBuilder(GenerisUserService::class) ->disableOriginalConstructor() ->onlyMethods(['getUser']) ->getMock(); $generisUserServiceMock->expects($this->once()) ->method('getUser') ->with($testId) ->willReturn($testUser); $generisUserServiceMock->setServiceLocator($serviceLocator); $this->assertSame([$testId => $testUser], $generisUserServiceMock->findUser($searchString)); } }