summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-10-10 14:54:15 +0200
committerGitHub <noreply@github.com>2018-10-10 14:54:15 +0200
commit0acae1d4aa45ea45428cc034f293f43c0f9430dc (patch)
tree2a32e5b33788248ac32cd217309d00f82b2cdd45 /apps
parenteac04adaddafc36bd8fc9f81cf6df12ed1050356 (diff)
parent78cc4171ee410660771bccc479a64e8d50139c24 (diff)
downloadnextcloud-server-0acae1d4aa45ea45428cc034f293f43c0f9430dc.tar.gz
nextcloud-server-0acae1d4aa45ea45428cc034f293f43c0f9430dc.zip
Merge pull request #11719 from nextcloud/techdebt/noid/allow-to-mock-new-datetime
Allow to inject/mock `new \DateTime()` similar to time()
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/tests/ExpirationTest.php54
-rw-r--r--apps/files_versions/tests/ExpirationTest.php53
2 files changed, 24 insertions, 83 deletions
diff --git a/apps/files_trashbin/tests/ExpirationTest.php b/apps/files_trashbin/tests/ExpirationTest.php
index 396fbdfb887..7bfbea19256 100644
--- a/apps/files_trashbin/tests/ExpirationTest.php
+++ b/apps/files_trashbin/tests/ExpirationTest.php
@@ -23,8 +23,9 @@
*/
use OCA\Files_Trashbin\Expiration;
-use \OCA\Files_Trashbin\Tests;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
class ExpirationTest extends \Test\TestCase {
const SECONDS_PER_DAY = 86400; //60*60*24
@@ -182,58 +183,27 @@ class ExpirationTest extends \Test\TestCase {
}
/**
- *
* @param int $time
- * @return \OCP\AppFramework\Utility\ITimeFactory
+ * @return ITimeFactory|MockObject
*/
private function getMockedTimeFactory($time){
- $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
- ->disableOriginalConstructor()
- ->setMethods(['getTime'])
- ->getMock()
- ;
- $mockedTimeFactory->expects($this->any())->method('getTime')->will(
- $this->returnValue($time)
- );
+ $mockedTimeFactory = $this->createMock(ITimeFactory::class);
+ $mockedTimeFactory->expects($this->any())
+ ->method('getTime')
+ ->willReturn($time);
return $mockedTimeFactory;
}
/**
- *
* @param string $returnValue
- * @return IConfig
+ * @return IConfig|MockObject
*/
private function getMockedConfig($returnValue){
- $mockedConfig = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->setMethods(
- [
- 'setSystemValues',
- 'setSystemValue',
- 'getSystemValue',
- 'getFilteredSystemValue',
- 'deleteSystemValue',
- 'getAppKeys',
- 'setAppValue',
- 'getAppValue',
- 'deleteAppValue',
- 'deleteAppValues',
- 'setUserValue',
- 'getUserValue',
- 'getUserValueForUsers',
- 'getUserKeys',
- 'deleteUserValue',
- 'deleteAllUserValues',
- 'deleteAppFromAllUsers',
- 'getUsersForUserValue'
- ]
- )
- ->getMock()
- ;
- $mockedConfig->expects($this->any())->method('getSystemValue')->will(
- $this->returnValue($returnValue)
- );
+ $mockedConfig = $this->createMock(IConfig::class);
+ $mockedConfig->expects($this->any())
+ ->method('getSystemValue')
+ ->willReturn($returnValue);
return $mockedConfig;
}
diff --git a/apps/files_versions/tests/ExpirationTest.php b/apps/files_versions/tests/ExpirationTest.php
index 8cd288d75cc..a7c34b7ac70 100644
--- a/apps/files_versions/tests/ExpirationTest.php
+++ b/apps/files_versions/tests/ExpirationTest.php
@@ -25,7 +25,9 @@
namespace OCA\Files_Versions\Tests;
use \OCA\Files_Versions\Expiration;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
class ExpirationTest extends \Test\TestCase {
const SECONDS_PER_DAY = 86400; //60*60*24
@@ -151,58 +153,27 @@ class ExpirationTest extends \Test\TestCase {
}
/**
- *
* @param int $time
- * @return \OCP\AppFramework\Utility\ITimeFactory
+ * @return ITimeFactory|MockObject
*/
private function getMockedTimeFactory($time){
- $mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
- ->disableOriginalConstructor()
- ->setMethods(['getTime'])
- ->getMock()
- ;
- $mockedTimeFactory->expects($this->any())->method('getTime')->will(
- $this->returnValue($time)
- );
+ $mockedTimeFactory = $this->createMock(ITimeFactory::class);
+ $mockedTimeFactory->expects($this->any())
+ ->method('getTime')
+ ->willReturn($time);
return $mockedTimeFactory;
}
/**
- *
* @param string $returnValue
- * @return \OCP\IConfig
+ * @return IConfig|MockObject
*/
private function getMockedConfig($returnValue){
- $mockedConfig = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->setMethods(
- [
- 'setSystemValues',
- 'setSystemValue',
- 'getSystemValue',
- 'getFilteredSystemValue',
- 'deleteSystemValue',
- 'getAppKeys',
- 'setAppValue',
- 'getAppValue',
- 'deleteAppValue',
- 'deleteAppValues',
- 'setUserValue',
- 'getUserValue',
- 'getUserValueForUsers',
- 'getUserKeys',
- 'deleteUserValue',
- 'deleteAllUserValues',
- 'deleteAppFromAllUsers',
- 'getUsersForUserValue'
- ]
- )
- ->getMock()
- ;
- $mockedConfig->expects($this->any())->method('getSystemValue')->will(
- $this->returnValue($returnValue)
- );
+ $mockedConfig = $this->createMock(IConfig::class);
+ $mockedConfig->expects($this->any())
+ ->method('getSystemValue')
+ ->willReturn($returnValue);
return $mockedConfig;
}