From bd70221d61b7467e2ab3eaf20243f114c0787989 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 29 Sep 2016 00:03:29 +0200 Subject: Mock HTTPClientService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These tests were not using any kind of mocks at all! This made the test execution time took 2 minutes instead of now less than 1 second… (because multiple HTTP requests were queued and timed-out then…) See https://blackfire.io/profiles/compare/6d2611f2-ad08-47b6-973b-2b5f9c8b96d2/graph for reference Signed-off-by: Lukas Reschke --- .../Controller/RequestHandlerControllerTest.php | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'apps/federatedfilesharing/tests') diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php index 8e1000fb500..18d698d398e 100644 --- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php +++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php @@ -31,6 +31,9 @@ use OC\Files\Filesystem; use OCA\FederatedFileSharing\DiscoveryManager; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\Controller\RequestHandlerController; +use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; +use OCP\Http\Client\IResponse; use OCP\IUserManager; use OCP\Share\IShare; @@ -242,15 +245,31 @@ class RequestHandlerControllerTest extends TestCase { function testDeleteUser($toDelete, $expected, $remainingUsers) { $this->createDummyS2SShares(); + $httpClientService = $this->createMock(IClientService::class); + $client = $this->createMock(IClient::class); + $response = $this->createMock(IResponse::class); + $client + ->expects($this->any()) + ->method('get') + ->willReturn($response); + $client + ->expects($this->any()) + ->method('post') + ->willReturn($response); + $httpClientService + ->expects($this->any()) + ->method('newClient') + ->willReturn($client); + $discoveryManager = new DiscoveryManager( \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() + $httpClientService ); $manager = new \OCA\Files_Sharing\External\Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPClientService(), + $httpClientService, \OC::$server->getNotificationManager(), $discoveryManager, $toDelete -- cgit v1.2.3