summaryrefslogtreecommitdiffstats
path: root/apps/federation/tests/Controller
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-08-01 11:23:40 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-08-01 11:23:40 +0200
commitbc54e6ff7cf6bb587feb5bf93b24b023a07a4123 (patch)
treead5a45004bfc52b59b274f350abd76fd29fe5645 /apps/federation/tests/Controller
parent3ffff08819365e6a38e0c7d381343f59bc2fc89c (diff)
downloadnextcloud-server-bc54e6ff7cf6bb587feb5bf93b24b023a07a4123.tar.gz
nextcloud-server-bc54e6ff7cf6bb587feb5bf93b24b023a07a4123.zip
Use ITimeFactory
* Inject the timefacotry so we can mock it properly in the tests. * Extended unit tests to cover the new paths Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/federation/tests/Controller')
-rw-r--r--apps/federation/tests/Controller/OCSAuthAPIControllerTest.php68
1 files changed, 35 insertions, 33 deletions
diff --git a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
index d0529583309..ef6c7c80bfc 100644
--- a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
+++ b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
@@ -29,8 +29,8 @@ use OC\BackgroundJob\JobList;
use OCA\Federation\Controller\OCSAuthAPIController;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
-use OCP\AppFramework\Http;
use OCP\AppFramework\OCS\OCSForbiddenException;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ILogger;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
@@ -38,24 +38,28 @@ use Test\TestCase;
class OCSAuthAPIControllerTest extends TestCase {
- /** @var \PHPUnit_Framework_MockObject_MockObject | IRequest */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|IRequest */
private $request;
- /** @var \PHPUnit_Framework_MockObject_MockObject | ISecureRandom */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|ISecureRandom */
private $secureRandom;
- /** @var \PHPUnit_Framework_MockObject_MockObject | JobList */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|JobList */
private $jobList;
- /** @var \PHPUnit_Framework_MockObject_MockObject | TrustedServers */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|TrustedServers */
private $trustedServers;
- /** @var \PHPUnit_Framework_MockObject_MockObject | DbHandler */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|DbHandler */
private $dbHandler;
- /** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */
+ /** @var \PHPUnit_Framework_MockObject_MockObject|ILogger */
private $logger;
+ /** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory */
+ private $timeFactory;
+
+
/** @var OCSAuthAPIController */
private $ocsAuthApi;
@@ -65,31 +69,28 @@ class OCSAuthAPIControllerTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->request = $this->getMockBuilder('OCP\IRequest')->getMock();
- $this->secureRandom = $this->getMockBuilder('OCP\Security\ISecureRandom')->getMock();
- $this->trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers')
- ->disableOriginalConstructor()->getMock();
- $this->dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
- ->disableOriginalConstructor()->getMock();
- $this->jobList = $this->getMockBuilder('OC\BackgroundJob\JobList')
- ->disableOriginalConstructor()->getMock();
- $this->logger = $this->getMockBuilder('OCP\ILogger')
- ->disableOriginalConstructor()->getMock();
-
- $this->ocsAuthApi = $this->getMockBuilder(OCSAuthAPIController::class)
- ->setConstructorArgs(
- [
- 'federation',
- $this->request,
- $this->secureRandom,
- $this->jobList,
- $this->trustedServers,
- $this->dbHandler,
- $this->logger
- ]
- )->setMethods(['getTimestamp'])->getMock();
-
- $this->ocsAuthApi->expects($this->any())->method('getTimestamp')->willReturn($this->currentTime);
+ $this->request = $this->createMock(IRequest::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
+ $this->dbHandler = $this->createMock(DbHandler::class);
+ $this->jobList = $this->createMock(JobList::class);
+ $this->logger = $this->createMock(ILogger::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+
+
+ $this->ocsAuthApi = new OCSAuthAPIController(
+ 'federation',
+ $this->request,
+ $this->secureRandom,
+ $this->jobList,
+ $this->trustedServers,
+ $this->dbHandler,
+ $this->logger,
+ $this->timeFactory
+ );
+
+ $this->timeFactory->method('getTime')
+ ->willReturn($this->currentTime);
}
@@ -157,7 +158,8 @@ class OCSAuthAPIControllerTest extends TestCase {
$this->jobList,
$this->trustedServers,
$this->dbHandler,
- $this->logger
+ $this->logger,
+ $this->timeFactory
]
)->setMethods(['isValidToken'])->getMock();