update unit tests

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-07-28 15:37:09 +02:00 committed by Roeland Jago Douma
parent 9c9cb1a6db
commit 80c08e8fd0
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 34 additions and 12 deletions

View File

@ -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);

View File

@ -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);