diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-07-28 15:37:09 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-08-01 10:07:53 +0200 |
commit | 80c08e8fd0b1d604d333e4bd38b229ce1ae579b9 (patch) | |
tree | 7c517b9b795d9cf4bb0692812f83155efbe81285 /apps/federation | |
parent | 9c9cb1a6dbb8cc57923a6516bea451454a662622 (diff) | |
download | nextcloud-server-80c08e8fd0b1d604d333e4bd38b229ce1ae579b9.tar.gz nextcloud-server-80c08e8fd0b1d604d333e4bd38b229ce1ae579b9.zip |
update unit tests
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/federation')
-rw-r--r-- | apps/federation/tests/BackgroundJob/GetSharedSecretTest.php | 18 | ||||
-rw-r--r-- | apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php | 28 |
2 files changed, 34 insertions, 12 deletions
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php index 6364ddaedff..5006ce1c2ab 100644 --- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php +++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php @@ -33,6 +33,7 @@ use OCA\Federation\TrustedServers; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\ILogger; use OCP\IURLGenerator; @@ -50,6 +51,9 @@ class GetSharedSecretTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | IClient */ private $httpClient; + /** @var \PHPUnit_Framework_MockObject_MockObject | IClientService */ + private $httpClientService; + /** @var \PHPUnit_Framework_MockObject_MockObject | IJobList */ private $jobList; @@ -77,6 +81,7 @@ class GetSharedSecretTest extends TestCase { public function setUp() { parent::setUp(); + $this->httpClientService = $this->createMock(IClientService::class); $this->httpClient = $this->getMockBuilder(IClient::class)->getMock(); $this->jobList = $this->getMockBuilder(IJobList::class)->getMock(); $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); @@ -89,9 +94,10 @@ class GetSharedSecretTest extends TestCase { $this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock(); $this->discoverService->expects($this->any())->method('discover')->willReturn([]); + $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); $this->getSharedSecret = new GetSharedSecret( - $this->httpClient, + $this->httpClientService, $this->urlGenerator, $this->jobList, $this->trustedServers, @@ -112,7 +118,7 @@ class GetSharedSecretTest extends TestCase { $getSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\GetSharedSecret') ->setConstructorArgs( [ - $this->httpClient, + $this->httpClientService, $this->urlGenerator, $this->jobList, $this->trustedServers, @@ -120,7 +126,7 @@ class GetSharedSecretTest extends TestCase { $this->dbHandler, $this->discoverService ] - )->setMethods(['parentExecute'])->getMock(); + )->setMethods(['parentExecute', 'reAddJob'])->getMock(); $this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url']]); $this->trustedServers->expects($this->once())->method('isTrustedServer') @@ -131,10 +137,12 @@ class GetSharedSecretTest extends TestCase { $getSharedSecret->expects($this->never())->method('parentExecute'); } $this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]); + $this->jobList->expects($this->once())->method('remove'); if ($retainBackgroundJob) { - $this->jobList->expects($this->never())->method('remove'); + $getSharedSecret->expects($this->once())->method('reAddJob'); } else { - $this->jobList->expects($this->once())->method('remove'); + $getSharedSecret->expects($this->never())->method('reAddJob'); + } $getSharedSecret->execute($this->jobList); diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php index 06da29d17fc..807ee2c000a 100644 --- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php +++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php @@ -31,13 +31,18 @@ use OCA\Federation\TrustedServers; use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; +use OCP\ILogger; use OCP\IURLGenerator; use OCP\OCS\IDiscoveryService; use Test\TestCase; class RequestSharedSecretTest extends TestCase { + /** @var \PHPUnit_Framework_MockObject_MockObject | IClientService */ + private $httpClientService; + /** @var \PHPUnit_Framework_MockObject_MockObject | IClient */ private $httpClient; @@ -59,12 +64,16 @@ class RequestSharedSecretTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject | IDiscoveryService */ private $discoveryService; + /** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */ + private $logger; + /** @var RequestSharedSecret */ private $requestSharedSecret; public function setUp() { parent::setUp(); + $this->httpClientService = $this->createMock(IClientService::class); $this->httpClient = $this->getMockBuilder(IClient::class)->getMock(); $this->jobList = $this->getMockBuilder(IJobList::class)->getMock(); $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); @@ -74,16 +83,19 @@ class RequestSharedSecretTest extends TestCase { ->disableOriginalConstructor()->getMock(); $this->response = $this->getMockBuilder(IResponse::class)->getMock(); $this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock(); + $this->logger = $this->createMock(ILogger::class); $this->discoveryService->expects($this->any())->method('discover')->willReturn([]); + $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); $this->requestSharedSecret = new RequestSharedSecret( - $this->httpClient, + $this->httpClientService, $this->urlGenerator, $this->jobList, $this->trustedServers, $this->dbHandler, - $this->discoveryService + $this->discoveryService, + $this->logger ); } @@ -98,14 +110,15 @@ class RequestSharedSecretTest extends TestCase { $requestSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\RequestSharedSecret') ->setConstructorArgs( [ - $this->httpClient, + $this->httpClientService, $this->urlGenerator, $this->jobList, $this->trustedServers, $this->dbHandler, - $this->discoveryService + $this->discoveryService, + $this->logger ] - )->setMethods(['parentExecute'])->getMock(); + )->setMethods(['parentExecute', 'reAddJob'])->getMock(); $this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url']]); $this->trustedServers->expects($this->once())->method('isTrustedServer') @@ -116,10 +129,11 @@ class RequestSharedSecretTest extends TestCase { $requestSharedSecret->expects($this->never())->method('parentExecute'); } $this->invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]); + $this->jobList->expects($this->once())->method('remove'); if ($retainBackgroundJob) { - $this->jobList->expects($this->never())->method('remove'); + $requestSharedSecret->expects($this->once())->method('reAddJob'); } else { - $this->jobList->expects($this->once())->method('remove'); + $requestSharedSecret->expects($this->never())->method('reAddJob'); } $requestSharedSecret->execute($this->jobList); |