Fix mock of ITimeFactory

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-10-10 10:17:56 +02:00
parent 840dd4b39c
commit 78cc4171ee
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 24 additions and 83 deletions

View File

@ -23,8 +23,9 @@
*/ */
use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Expiration;
use \OCA\Files_Trashbin\Tests; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
class ExpirationTest extends \Test\TestCase { class ExpirationTest extends \Test\TestCase {
const SECONDS_PER_DAY = 86400; //60*60*24 const SECONDS_PER_DAY = 86400; //60*60*24
@ -182,58 +183,27 @@ class ExpirationTest extends \Test\TestCase {
} }
/** /**
*
* @param int $time * @param int $time
* @return \OCP\AppFramework\Utility\ITimeFactory * @return ITimeFactory|MockObject
*/ */
private function getMockedTimeFactory($time){ private function getMockedTimeFactory($time){
$mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') $mockedTimeFactory = $this->createMock(ITimeFactory::class);
->disableOriginalConstructor() $mockedTimeFactory->expects($this->any())
->setMethods(['getTime']) ->method('getTime')
->getMock() ->willReturn($time);
;
$mockedTimeFactory->expects($this->any())->method('getTime')->will(
$this->returnValue($time)
);
return $mockedTimeFactory; return $mockedTimeFactory;
} }
/** /**
*
* @param string $returnValue * @param string $returnValue
* @return IConfig * @return IConfig|MockObject
*/ */
private function getMockedConfig($returnValue){ private function getMockedConfig($returnValue){
$mockedConfig = $this->getMockBuilder(IConfig::class) $mockedConfig = $this->createMock(IConfig::class);
->disableOriginalConstructor() $mockedConfig->expects($this->any())
->setMethods( ->method('getSystemValue')
[ ->willReturn($returnValue);
'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)
);
return $mockedConfig; return $mockedConfig;
} }

View File

@ -25,7 +25,9 @@
namespace OCA\Files_Versions\Tests; namespace OCA\Files_Versions\Tests;
use \OCA\Files_Versions\Expiration; use \OCA\Files_Versions\Expiration;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
class ExpirationTest extends \Test\TestCase { class ExpirationTest extends \Test\TestCase {
const SECONDS_PER_DAY = 86400; //60*60*24 const SECONDS_PER_DAY = 86400; //60*60*24
@ -151,58 +153,27 @@ class ExpirationTest extends \Test\TestCase {
} }
/** /**
*
* @param int $time * @param int $time
* @return \OCP\AppFramework\Utility\ITimeFactory * @return ITimeFactory|MockObject
*/ */
private function getMockedTimeFactory($time){ private function getMockedTimeFactory($time){
$mockedTimeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory') $mockedTimeFactory = $this->createMock(ITimeFactory::class);
->disableOriginalConstructor() $mockedTimeFactory->expects($this->any())
->setMethods(['getTime']) ->method('getTime')
->getMock() ->willReturn($time);
;
$mockedTimeFactory->expects($this->any())->method('getTime')->will(
$this->returnValue($time)
);
return $mockedTimeFactory; return $mockedTimeFactory;
} }
/** /**
*
* @param string $returnValue * @param string $returnValue
* @return \OCP\IConfig * @return IConfig|MockObject
*/ */
private function getMockedConfig($returnValue){ private function getMockedConfig($returnValue){
$mockedConfig = $this->getMockBuilder(IConfig::class) $mockedConfig = $this->createMock(IConfig::class);
->disableOriginalConstructor() $mockedConfig->expects($this->any())
->setMethods( ->method('getSystemValue')
[ ->willReturn($returnValue);
'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)
);
return $mockedConfig; return $mockedConfig;
} }