From 4066f04c4b74c54450559042256e910a19e4a68b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 19:36:22 +0200 Subject: [PATCH 01/22] Fix getMock MapperTestUtility --- tests/lib/AppFramework/Db/MapperTestUtility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/AppFramework/Db/MapperTestUtility.php b/tests/lib/AppFramework/Db/MapperTestUtility.php index 69f0ad4eb67bf..bbc9b56701e79 100644 --- a/tests/lib/AppFramework/Db/MapperTestUtility.php +++ b/tests/lib/AppFramework/Db/MapperTestUtility.php @@ -49,7 +49,7 @@ protected function setUp(){ ->disableOriginalConstructor() ->getMock(); - $this->query = $this->getMock('\PDOStatement'); + $this->query = $this->createMock('\PDOStatement'); $this->queryAt = 0; $this->prepareAt = 0; $this->iterators = []; From 9ea2153e9be84a7a0bafc469289b66669bba9852 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 19:42:23 +0200 Subject: [PATCH 02/22] Fix getMock Command/Intergrity --- tests/lib/Command/Integrity/SignAppTest.php | 35 ++++++++++---------- tests/lib/Command/Integrity/SignCoreTest.php | 28 ++++++++-------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/tests/lib/Command/Integrity/SignAppTest.php b/tests/lib/Command/Integrity/SignAppTest.php index 44a644c45dfb9..71d9946ee889f 100644 --- a/tests/lib/Command/Integrity/SignAppTest.php +++ b/tests/lib/Command/Integrity/SignAppTest.php @@ -24,6 +24,8 @@ use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Helpers\FileAccessHelper; use OCP\IURLGenerator; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class SignAppTest extends TestCase { @@ -38,12 +40,9 @@ class SignAppTest extends TestCase { public function setUp() { parent::setUp(); - $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') - ->disableOriginalConstructor()->getMock(); - $this->fileAccessHelper = $this->getMockBuilder('\OC\IntegrityCheck\Helpers\FileAccessHelper') - ->disableOriginalConstructor()->getMock(); - $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') - ->disableOriginalConstructor()->getMock(); + $this->checker = $this->createMock(Checker::class); + $this->fileAccessHelper = $this->createMock(FileAccessHelper::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->signApp = new SignApp( $this->checker, $this->fileAccessHelper, @@ -52,8 +51,8 @@ public function setUp() { } public function testExecuteWithMissingPath() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -80,8 +79,8 @@ public function testExecuteWithMissingPath() { } public function testExecuteWithMissingPrivateKey() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -108,8 +107,8 @@ public function testExecuteWithMissingPrivateKey() { } public function testExecuteWithMissingCertificate() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -136,8 +135,8 @@ public function testExecuteWithMissingCertificate() { } public function testExecuteWithNotExistingPrivateKey() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -170,8 +169,8 @@ public function testExecuteWithNotExistingPrivateKey() { } public function testExecuteWithNotExistingCertificate() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -209,8 +208,8 @@ public function testExecuteWithNotExistingCertificate() { } public function testExecute() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) diff --git a/tests/lib/Command/Integrity/SignCoreTest.php b/tests/lib/Command/Integrity/SignCoreTest.php index ff1f6b23a95ba..f3c242ae9fb5f 100644 --- a/tests/lib/Command/Integrity/SignCoreTest.php +++ b/tests/lib/Command/Integrity/SignCoreTest.php @@ -23,6 +23,8 @@ use OC\Core\Command\Integrity\SignCore; use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Helpers\FileAccessHelper; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; class SignCoreTest extends TestCase { @@ -35,10 +37,8 @@ class SignCoreTest extends TestCase { public function setUp() { parent::setUp(); - $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') - ->disableOriginalConstructor()->getMock(); - $this->fileAccessHelper = $this->getMockBuilder('\OC\IntegrityCheck\Helpers\FileAccessHelper') - ->disableOriginalConstructor()->getMock(); + $this->checker = $this->createMock(Checker::class); + $this->fileAccessHelper = $this->createMock(FileAccessHelper::class); $this->signCore = new SignCore( $this->checker, $this->fileAccessHelper @@ -46,8 +46,8 @@ public function setUp() { } public function testExecuteWithMissingPrivateKey() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -69,8 +69,8 @@ public function testExecuteWithMissingPrivateKey() { } public function testExecuteWithMissingCertificate() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -92,8 +92,8 @@ public function testExecuteWithMissingCertificate() { } public function testExecuteWithNotExistingPrivateKey() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -126,8 +126,8 @@ public function testExecuteWithNotExistingPrivateKey() { } public function testExecuteWithNotExistingCertificate() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) @@ -165,8 +165,8 @@ public function testExecuteWithNotExistingCertificate() { } public function testExecute() { - $inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface'); - $outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface'); + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); $inputInterface ->expects($this->at(0)) From 4da1ee99d687d27f82e32f53af74ff52a35c36f9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 19:51:45 +0200 Subject: [PATCH 03/22] Fix getMock Encryption --- .../lib/Encryption/EncryptionWrapperTest.php | 11 +++++---- tests/lib/Encryption/ManagerTest.php | 23 ++++++++++++------- tests/lib/Encryption/UtilTest.php | 5 ++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php index 909187ae43b4c..6599428b36475 100644 --- a/tests/lib/Encryption/EncryptionWrapperTest.php +++ b/tests/lib/Encryption/EncryptionWrapperTest.php @@ -24,6 +24,9 @@ use OC\Encryption\EncryptionWrapper; +use OC\Encryption\Manager; +use OC\Memcache\ArrayCache; +use OCP\ILogger; use Test\TestCase; class EncryptionWrapperTest extends TestCase { @@ -43,10 +46,10 @@ class EncryptionWrapperTest extends TestCase { public function setUp() { parent::setUp(); - $this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); - $this->manager = $this->getMockBuilder('OC\Encryption\Manager') - ->disableOriginalConstructor()->getMock(); - $this->logger = $this->getMock('OCP\ILogger'); + $this->arrayCache = $this->createMock(ArrayCache::class); + $this->manager = $this->createMock(Manager::class); + $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(ILogger::class); $this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger); } diff --git a/tests/lib/Encryption/ManagerTest.php b/tests/lib/Encryption/ManagerTest.php index 3dcfc949a1826..ad7f47e0a3ea7 100644 --- a/tests/lib/Encryption/ManagerTest.php +++ b/tests/lib/Encryption/ManagerTest.php @@ -3,6 +3,13 @@ namespace Test\Encryption; use OC\Encryption\Manager; +use OC\Encryption\Util; +use OC\Files\View; +use OC\Memcache\ArrayCache; +use OCP\Encryption\IEncryptionModule; +use OCP\IConfig; +use OCP\IL10N; +use OCP\ILogger; use Test\TestCase; class ManagerTest extends TestCase { @@ -30,12 +37,12 @@ class ManagerTest extends TestCase { public function setUp() { parent::setUp(); - $this->config = $this->getMock('\OCP\IConfig'); - $this->logger = $this->getMock('\OCP\ILogger'); - $this->l10n = $this->getMock('\OCP\Il10n'); - $this->view = $this->getMock('\OC\Files\View'); - $this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock(); - $this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); + $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(ILogger::class); + $this->l10n = $this->createMock(IL10N::class); + $this->view = $this->createMock(View::class); + $this->util = $this->createMock(Util::class); + $this->arrayCache = $this->createMock(ArrayCache::class); $this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util, $this->arrayCache); } @@ -50,7 +57,7 @@ public function testManagerIsDisabledIfEnabledButNoModules() { public function testManagerIsDisabledIfDisabledButModules() { $this->config->expects($this->any())->method('getAppValue')->willReturn(false); - $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); + $em = $this->createMock(IEncryptionModule::class); $em->expects($this->any())->method('getId')->willReturn('id'); $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0'); $this->manager->registerEncryptionModule('id', 'TestDummyModule0', function() use ($em) {return $em;}); @@ -235,7 +242,7 @@ public function testSetDefaultEncryptionModule() { // } protected function addNewEncryptionModule(Manager $manager, $id) { - $encryptionModule = $this->getMock('\OCP\Encryption\IEncryptionModule'); + $encryptionModule = $this->createMock(IEncryptionModule::class); $encryptionModule->expects($this->any()) ->method('getId') ->willReturn('ID' . $id); diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index ec316a9f05a69..609f6ae1e68ec 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -3,6 +3,7 @@ namespace Test\Encryption; use OC\Encryption\Util; +use OCP\Encryption\IEncryptionModule; use Test\TestCase; class UtilTest extends TestCase { @@ -77,7 +78,7 @@ public function providesHeadersForEncryptionModule() { */ public function testCreateHeader($expected, $header, $moduleId) { - $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); + $em = $this->createMock(IEncryptionModule::class); $em->expects($this->any())->method('getId')->willReturn($moduleId); $result = $this->util->createHeader($header, $em); @@ -100,7 +101,7 @@ public function testCreateHeaderFailed() { $header = array('header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo'); - $em = $this->getMock('\OCP\Encryption\IEncryptionModule'); + $em = $this->createMock(IEncryptionModule::class); $em->expects($this->any())->method('getId')->willReturn('moduleId'); $this->util->createHeader($header, $em); From a819fd3f1eb455871ce424efc8be311582a1d43a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 19:52:50 +0200 Subject: [PATCH 04/22] Fix getMock FileChunkingTest --- tests/lib/FileChunkingTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/FileChunkingTest.php b/tests/lib/FileChunkingTest.php index 66888285d23bb..cf0fed251a46e 100644 --- a/tests/lib/FileChunkingTest.php +++ b/tests/lib/FileChunkingTest.php @@ -20,6 +20,8 @@ */ namespace Test; +use OCP\ICache; + class FileChunkingTest extends \Test\TestCase { public function dataIsComplete() { @@ -54,7 +56,7 @@ public function testIsComplete($total, array $present, $expected) { ]]) ->getMock(); - $cache = $this->getMock('\OCP\ICache'); + $cache = $this->createMock(ICache::class); $cache->expects($this->atLeastOnce()) ->method('hasKey') From 7656a8fa1210c096e677720f8ba0ab93affdd0e3 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:01:13 +0200 Subject: [PATCH 05/22] File getMock Files tests --- tests/lib/Files/Mount/MountPointTest.php | 9 ++++++--- .../Mount/ObjectHomeMountProviderTest.php | 8 ++++---- tests/lib/Files/ObjectStore/MapperTest.php | 5 +++-- .../Files/Storage/Wrapper/EncryptionTest.php | 19 +++++++++++-------- tests/lib/Files/Stream/EncryptionTest.php | 12 ++++++------ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php index 799f441a1aba6..03b106eb598bc 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -8,15 +8,18 @@ namespace Test\Files\Mount; +use OC\Files\Storage\StorageFactory; +use OCP\Files\Storage; + class MountPointTest extends \Test\TestCase { public function testGetStorage() { - $storage = $this->getMock('\OCP\Files\Storage'); + $storage = $this->createMock(Storage::class); $storage->expects($this->once()) ->method('getId') ->will($this->returnValue(123)); - $loader = $this->getMock('\OC\Files\Storage\StorageFactory'); + $loader = $this->createMock(StorageFactory::class); $loader->expects($this->once()) ->method('wrap') ->will($this->returnValue($storage)); @@ -38,7 +41,7 @@ public function testGetStorage() { } public function testInvalidStorage() { - $loader = $this->getMock('\OC\Files\Storage\StorageFactory'); + $loader = $this->createMock(StorageFactory::class); $loader->expects($this->once()) ->method('wrap') ->will($this->throwException(new \Exception('Test storage init exception'))); diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php index 5d987f0d059fe..0af90991d60ff 100644 --- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php +++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php @@ -24,9 +24,9 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { public function setUp() { parent::setUp(); - $this->config = $this->getMock('OCP\IConfig'); - $this->user = $this->getMock('OCP\IUser'); - $this->loader = $this->getMock('OCP\Files\Storage\IStorageFactory'); + $this->config = $this->createMock(IConfig::class); + $this->user = $this->createMock(IUser::class); + $this->loader = $this->createMock(IStorageFactory::class); $this->provider = new ObjectHomeMountProvider($this->config); } @@ -241,4 +241,4 @@ public function __construct(array $arguments) { public function getArguments() { return $this->arguments; } -} \ No newline at end of file +} diff --git a/tests/lib/Files/ObjectStore/MapperTest.php b/tests/lib/Files/ObjectStore/MapperTest.php index 1ebb67a6905a0..18bdcdfd0055c 100644 --- a/tests/lib/Files/ObjectStore/MapperTest.php +++ b/tests/lib/Files/ObjectStore/MapperTest.php @@ -22,6 +22,7 @@ use OC\Files\ObjectStore\Mapper; +use OCP\IUser; class MapperTest extends \Test\TestCase { @@ -39,7 +40,7 @@ public function dataGetBucket() { * @param string $expectedBucket */ public function testGetBucket($username, $expectedBucket) { - $user = $this->getMock('OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn($username); @@ -47,4 +48,4 @@ public function testGetBucket($username, $expectedBucket) { $this->assertSame($expectedBucket, $mapper->getBucket()); } -} \ No newline at end of file +} diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index e9ebf2f3bdfba..55b38d546decc 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -5,7 +5,10 @@ use OC\Encryption\Util; use OC\Files\Storage\Temporary; use OC\Files\View; +use OC\Log; +use OC\Memcache\ArrayCache; use OC\User\Manager; +use OCP\Files\Cache\ICache; use Test\Files\Storage\Storage; class EncryptionTest extends Storage { @@ -108,7 +111,7 @@ protected function setUp() { ->method('getEncryptionModule') ->willReturn($mockModule); - $this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); + $this->arrayCache = $this->createMock(ArrayCache::class); $this->config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); @@ -116,10 +119,10 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); - $this->util = $this->getMock( - '\OC\Encryption\Util', - ['getUidAndFilename', 'isFile', 'isExcluded'], - [new View(), new Manager(), $this->groupManager, $this->config, $this->arrayCache]); + $this->util = $this->getMockBuilder('\OC\Encryption\Util') + ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) + ->setConstructorArgs([new View(), new Manager(), $this->groupManager, $this->config, $this->arrayCache]) + ->getMock(); $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturnCallback(function ($path) { @@ -132,7 +135,7 @@ protected function setUp() { ->getMock(); $this->file->expects($this->any())->method('getAccessList')->willReturn([]); - $this->logger = $this->getMock('\OC\Log'); + $this->logger = $this->createMock(Log::class); $this->sourceStorage = new Temporary(array()); @@ -713,7 +716,7 @@ public function testCopyBetweenStorageMinimumEncryptedVersion() { $temp = \OC::$server->getTempManager(); return fopen($temp->getTemporaryFile(), $mode); }); - $cache = $this->getMock('\OCP\Files\Cache\ICache'); + $cache = $this->createMock(ICache::class); $cache->expects($this->once()) ->method('get') ->with($sourceInternalPath) @@ -763,7 +766,7 @@ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryption return fopen($temp->getTemporaryFile(), $mode); }); if($expectedEncrypted) { - $cache = $this->getMock('\OCP\Files\Cache\ICache'); + $cache = $this->createMock(ICache::class); $cache->expects($this->once()) ->method('get') ->with($sourceInternalPath) diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 45204e48d09a7..6f3c879f9e6fb 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -3,6 +3,7 @@ namespace Test\Files\Stream; use OC\Files\View; +use OC\Memcache\ArrayCache; class EncryptionTest extends \Test\TestCase { @@ -31,7 +32,7 @@ protected function getStream($fileName, $mode, $unencryptedSize, $wrapper = '\OC $config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $arrayCache = $this->getMock('OC\Memcache\ArrayCache'); + $arrayCache = $this->createMock(ArrayCache::class); $groupManager = $this->getMockBuilder('\OC\Group\Manager') ->disableOriginalConstructor() ->getMock(); @@ -40,11 +41,10 @@ protected function getStream($fileName, $mode, $unencryptedSize, $wrapper = '\OC ->setMethods(['getAccessList']) ->getMock(); $file->expects($this->any())->method('getAccessList')->willReturn([]); - $util = $this->getMock( - '\OC\Encryption\Util', - ['getUidAndFilename'], - [new View(), new \OC\User\Manager(), $groupManager, $config, $arrayCache] - ); + $util = $this->getMockBuilder('\OC\Encryption\Util') + ->setMethods(['getUidAndFilename']) + ->setConstructorArgs([new View(), new \OC\User\Manager(), $groupManager, $config, $arrayCache]) + ->getMock(); $util->expects($this->any()) ->method('getUidAndFilename') ->willReturn(['user1', $internalPath]); From 28c801b3d5e226ffb474fa888fe97f94579664b2 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:02:11 +0200 Subject: [PATCH 06/22] Fix getMock MetaDataTest --- tests/lib/Group/MetaDataTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/Group/MetaDataTest.php b/tests/lib/Group/MetaDataTest.php index 593bbcb48db22..04d2ff807b479 100644 --- a/tests/lib/Group/MetaDataTest.php +++ b/tests/lib/Group/MetaDataTest.php @@ -22,6 +22,8 @@ namespace Test\Group; +use OCP\IUserSession; + class MetaDataTest extends \Test\TestCase { /** @var \OC\Group\Manager */ private $groupManager; @@ -37,7 +39,7 @@ public function setUp() { $this->groupManager = $this->getMockBuilder('\OC\Group\Manager') ->disableOriginalConstructor() ->getMock(); - $this->userSession = $this->getMock('\OCP\IUserSession'); + $this->userSession = $this->createMock(IUserSession::class); $this->groupMetadata = new \OC\Group\MetaData( 'foo', $this->isAdmin, From aa670cab14d75fe04c97c3a61fd1a1d620f78e78 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:03:57 +0200 Subject: [PATCH 07/22] Fix getMock HTTPHelper --- tests/lib/HTTPHelperTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/HTTPHelperTest.php b/tests/lib/HTTPHelperTest.php index 6d9c478873567..d241acb2f9300 100644 --- a/tests/lib/HTTPHelperTest.php +++ b/tests/lib/HTTPHelperTest.php @@ -8,6 +8,8 @@ namespace Test; +use OCP\Http\Client\IClientService; + class HTTPHelperTest extends \Test\TestCase { /** @var \OCP\IConfig*/ @@ -22,7 +24,7 @@ protected function setUp() { $this->config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor()->getMock(); - $this->clientService = $this->getMock('\OCP\Http\Client\IClientService'); + $this->clientService = $this->createMock(IClientService::class); $this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper') ->setConstructorArgs(array($this->config, $this->clientService)) ->setMethods(array('getHeaders')) From 97f6410ac8561bbea2ea806bc6f23f67bef985e4 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:05:51 +0200 Subject: [PATCH 08/22] Fix getMock Http Client --- tests/lib/Http/Client/ClientServiceTest.php | 6 ++++-- tests/lib/Http/Client/ClientTest.php | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php index 3c406f3011146..48330dc33c0b1 100644 --- a/tests/lib/Http/Client/ClientServiceTest.php +++ b/tests/lib/Http/Client/ClientServiceTest.php @@ -11,14 +11,16 @@ use GuzzleHttp\Client as GuzzleClient; use OC\Http\Client\Client; use OC\Http\Client\ClientService; +use OCP\ICertificateManager; +use OCP\IConfig; /** * Class ClientServiceTest */ class ClientServiceTest extends \Test\TestCase { public function testNewClient() { - $config = $this->getMock('\OCP\IConfig'); - $certificateManager = $this->getMock('\OCP\ICertificateManager'); + $config = $this->createMock(IConfig::class); + $certificateManager = $this->createMock(ICertificateManager::class); $expected = new Client($config, $certificateManager, new GuzzleClient()); $clientService = new ClientService($config, $certificateManager); diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 705e1eeddea0b..4369eab3a54a4 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -10,6 +10,7 @@ use GuzzleHttp\Message\Response; use OC\Http\Client\Client; +use OCP\ICertificateManager; use OCP\IConfig; /** @@ -25,11 +26,11 @@ class ClientTest extends \Test\TestCase { public function setUp() { parent::setUp(); - $this->config = $this->getMock('\OCP\IConfig'); + $this->config = $this->createMock(IConfig::class); $this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client') ->disableOriginalConstructor() ->getMock(); - $certificateManager = $this->getMock('\OCP\ICertificateManager'); + $certificateManager = $this->createMock(ICertificateManager::class); $this->client = new Client( $this->config, $certificateManager, From ba3a90d30c2079a370d66bb9a143174d14cd48bc Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:07:44 +0200 Subject: [PATCH 09/22] Fix getMock checkertest --- tests/lib/IntegrityCheck/CheckerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index 6e6095668b06f..d67f1382dc9fb 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -51,12 +51,12 @@ class CheckerTest extends TestCase { public function setUp() { parent::setUp(); - $this->environmentHelper = $this->getMock('\OC\IntegrityCheck\Helpers\EnvironmentHelper'); - $this->fileAccessHelper = $this->getMock('\OC\IntegrityCheck\Helpers\FileAccessHelper'); - $this->appLocator = $this->getMock('\OC\IntegrityCheck\Helpers\AppLocator'); - $this->config = $this->getMock('\OCP\IConfig'); - $this->cacheFactory = $this->getMock('\OCP\ICacheFactory'); - $this->appManager = $this->getMock('\OCP\App\IAppManager'); + $this->environmentHelper = $this->createMock(EnvironmentHelper::class); + $this->fileAccessHelper = $this->createMock(FileAccessHelper::class); + $this->appLocator = $this->createMock(AppLocator::class); + $this->config = $this->createMock(IConfig::class); + $this->cacheFactory = $this->createMock(ICacheFactory::class); + $this->appManager = $this->createMock(IAppManager::class); $this->cacheFactory ->expects($this->any()) From f167e65d4904cdc1b2516a1058d48d4a9d22b5e0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:10:47 +0200 Subject: [PATCH 10/22] Fix getMock L10NTest --- tests/lib/L10N/L10nTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index 227e07056a854..6d662efee237a 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -12,6 +12,8 @@ use DateTime; use OC\L10N\Factory; use OC\L10N\L10N; +use OCP\IConfig; +use OCP\IRequest; use OCP\IUserSession; use Test\TestCase; @@ -26,11 +28,11 @@ class L10nTest extends TestCase { */ protected function getFactory() { /** @var \OCP\IConfig $config */ - $config = $this->getMock('OCP\IConfig'); + $config = $this->createMock(IConfig::class); /** @var \OCP\IRequest $request */ - $request = $this->getMock('OCP\IRequest'); + $request = $this->createMock(IRequest::class); /** @var IUserSession $userSession */ - $userSession = $this->getMock('OCP\IUserSession'); + $userSession = $this->createMock(IUserSession::class); return new Factory($config, $request, $userSession, \OC::$SERVERROOT); } From c95d5c77d7a9e4e1e10ea4a04c7548ac89a19ca3 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:11:43 +0200 Subject: [PATCH 11/22] Fix getMock LegacyHelperTest --- tests/lib/LegacyHelperTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index d8b1a82c2712e..faea95190ecf2 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -8,6 +8,7 @@ namespace Test; +use OC\Files\View; use OC_Helper; class LegacyHelperTest extends \Test\TestCase { @@ -129,7 +130,7 @@ function testRecursiveArraySearch() { } function testBuildNotExistingFileNameForView() { - $viewMock = $this->getMock('\OC\Files\View', array(), array(), '', false); + $viewMock = $this->createMock(View::class); $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock)); $this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); From b8b9fc2b1cc507ea491eb439a5088884cf1279b8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:15:19 +0200 Subject: [PATCH 12/22] Fix getMock OCSClient --- tests/lib/OCSClientTest.php | 54 +++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/tests/lib/OCSClientTest.php b/tests/lib/OCSClientTest.php index 4ae6fb62e0ebb..d4bfd77e87126 100644 --- a/tests/lib/OCSClientTest.php +++ b/tests/lib/OCSClientTest.php @@ -22,7 +22,9 @@ namespace Test; use OC\OCSClient; +use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; +use OCP\Http\Client\IResponse; use OCP\IConfig; use OCP\ILogger; @@ -44,8 +46,8 @@ public function setUp() { $this->config = $this->getMockBuilder('\OCP\IConfig') ->disableOriginalConstructor()->getMock(); - $this->clientService = $this->getMock('\OCP\Http\Client\IClientService'); - $this->logger = $this->getMock('\OCP\ILogger'); + $this->clientService = $this->createMock(IClientService::class); + $this->logger = $this->createMock(ILogger::class); $this->ocsClient = new OCSClient( $this->clientService, @@ -102,7 +104,7 @@ public function testGetCategoriesExceptionClient() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -145,13 +147,13 @@ public function testGetCategoriesParseError() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') ->will($this->returnValue('MyInvalidXml')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -194,7 +196,7 @@ public function testGetCategoriesSuccessful() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -235,7 +237,7 @@ public function testGetCategoriesSuccessful() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -285,7 +287,7 @@ public function testGetApplicationsExceptionClient() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -336,13 +338,13 @@ public function testGetApplicationsParseError() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') ->will($this->returnValue('MyInvalidXml')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -393,7 +395,7 @@ public function testGetApplicationsSuccessful() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -478,7 +480,7 @@ public function testGetApplicationsSuccessful() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -568,7 +570,7 @@ public function testGetApplicationExceptionClient() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -611,13 +613,13 @@ public function testGetApplicationParseError() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') ->will($this->returnValue('MyInvalidXml')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -660,7 +662,7 @@ public function testGetApplicationSuccessful() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -745,7 +747,7 @@ public function testGetApplicationSuccessful() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -796,7 +798,7 @@ public function testGetApplicationSuccessfulWithOldId() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -881,7 +883,7 @@ public function testGetApplicationSuccessfulWithOldId() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -932,7 +934,7 @@ public function testGetApplicationEmptyXml() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -946,7 +948,7 @@ public function testGetApplicationEmptyXml() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -988,7 +990,7 @@ public function testGetApplicationDownloadExceptionClient() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -1031,13 +1033,13 @@ public function testGetApplicationDownloadParseError() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') ->will($this->returnValue('MyInvalidXml')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') @@ -1080,7 +1082,7 @@ public function testGetApplicationDownloadUrlSuccessful() { ->with('appstoreurl', 'https://api.owncloud.com/v1') ->will($this->returnValue('https://api.owncloud.com/v1')); - $response = $this->getMock('\OCP\Http\Client\IResponse'); + $response = $this->createMock(IResponse::class); $response ->expects($this->once()) ->method('getBody') @@ -1104,7 +1106,7 @@ public function testGetApplicationDownloadUrlSuccessful() { ')); - $client = $this->getMock('\OCP\Http\Client\IClient'); + $client = $this->createMock(IClient::class); $client ->expects($this->once()) ->method('get') From 1b5ed67857a2281a4adb060175009e72bf8d49b5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:18:04 +0200 Subject: [PATCH 13/22] Fix getMock Migration --- tests/lib/Migration/BackgroundRepairTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/lib/Migration/BackgroundRepairTest.php b/tests/lib/Migration/BackgroundRepairTest.php index e092f6c2e8bb3..2de55f647e7f6 100644 --- a/tests/lib/Migration/BackgroundRepairTest.php +++ b/tests/lib/Migration/BackgroundRepairTest.php @@ -75,7 +75,9 @@ public function setUp() { $this->logger = $this->getMockBuilder('OCP\ILogger') ->disableOriginalConstructor() ->getMock(); - $this->job = $this->getMock('OC\Migration\BackgroundRepair', ['loadApp']); + $this->job = $this->getMockBuilder(BackgroundRepair::class) + ->setMethods(['loadApp']) + ->getMock(); } public function testNoArguments() { @@ -105,7 +107,7 @@ public function testUnknownStep() { public function testWorkingStep() { /** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject $dispatcher */ - $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher', []); + $dispatcher = $this->createMock(EventDispatcher::class); $dispatcher->expects($this->once())->method('dispatch') ->with('\OC\Repair::step', new GenericEvent('\OC\Repair::step', ['A test repair step'])); From dc60f4c441000b51ea8cba3b1ffca7f458bf52d5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:18:58 +0200 Subject: [PATCH 14/22] Fix getMock Repair --- tests/lib/Repair/RepairSharePropagationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/Repair/RepairSharePropagationTest.php b/tests/lib/Repair/RepairSharePropagationTest.php index 07db3c84f2869..d6010cf57067d 100644 --- a/tests/lib/Repair/RepairSharePropagationTest.php +++ b/tests/lib/Repair/RepairSharePropagationTest.php @@ -9,6 +9,7 @@ namespace Test\Repair; use OC\Repair\SharePropagation; +use OCP\IConfig; use OCP\Migration\IOutput; class RepairSharePropagationTest extends \Test\TestCase { @@ -27,7 +28,7 @@ public function keyProvider() { */ public function testRemovePropagationEntries(array $startKeys, array $expectedRemovedKeys) { /** @var \PHPUnit_Framework_MockObject_MockObject|\OCP\IConfig $config */ - $config = $this->getMock('\OCP\IConfig'); + $config = $this->createMock(IConfig::class); $config->expects($this->once()) ->method('getAppKeys') ->with('files_sharing') From e1096c964d4f509f2bcee55d1f6bd0a36517a3d9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:20:08 +0200 Subject: [PATCH 15/22] Fix getMock Security --- tests/lib/Security/Bruteforce/ThrottlerTest.php | 6 +++--- tests/lib/Security/CredentialsManagerTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/lib/Security/Bruteforce/ThrottlerTest.php b/tests/lib/Security/Bruteforce/ThrottlerTest.php index 9b7a47ceec89b..604aecd3a65b1 100644 --- a/tests/lib/Security/Bruteforce/ThrottlerTest.php +++ b/tests/lib/Security/Bruteforce/ThrottlerTest.php @@ -44,9 +44,9 @@ class ThrottlerTest extends TestCase { private $config; public function setUp() { - $this->dbConnection = $this->getMock('\OCP\IDBConnection'); - $this->logger = $this->getMock('\OCP\ILogger'); - $this->config = $this->getMock('\OCP\IConfig'); + $this->dbConnection = $this->createMock(IDBConnection::class); + $this->logger = $this->createMock(ILogger::class); + $this->config = $this->createMock(IConfig::class); $this->throttler = new Throttler( $this->dbConnection, diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index 7eb4e4d7b1a35..cffcc02817cd6 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -38,7 +38,7 @@ class CredentialsManagerTest extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->crypto = $this->getMock('\OCP\Security\ICrypto'); + $this->crypto = $this->createMock(ICrypto::class); $this->dbConnection = $this->getMockBuilder('\OC\DB\Connection') ->disableOriginalConstructor() ->getMock(); From 65409f53274e6dbbfdcac1726546b9fd32c99677 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:22:02 +0200 Subject: [PATCH 16/22] Fix getMock SetupTest --- tests/lib/SetupTest.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index c6e219f4029fb..a8389eaaf5636 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -8,7 +8,11 @@ namespace Test; +use bantu\IniGetWrapper\IniGetWrapper; use OCP\IConfig; +use OCP\IL10N; +use OCP\ILogger; +use OCP\Security\ISecureRandom; class SetupTest extends \Test\TestCase { @@ -30,15 +34,16 @@ class SetupTest extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->config = $this->getMock('\OCP\IConfig'); - $this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper'); - $this->l10n = $this->getMock('\OCP\IL10N'); - $this->defaults = $this->getMock('\OC_Defaults'); - $this->logger = $this->getMock('\OCP\ILogger'); - $this->random = $this->getMock('\OCP\Security\ISecureRandom'); - $this->setupClass = $this->getMock('\OC\Setup', - ['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'], - [$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]); + $this->config = $this->createMock(IConfig::class); + $this->iniWrapper = $this->createMock(IniGetWrapper::class); + $this->l10n = $this->createMock(IL10N::class); + $this->defaults = $this->createMock(\OC_Defaults::class); + $this->logger = $this->createMock(ILogger::class); + $this->random = $this->createMock(ISecureRandom::class); + $this->setupClass = $this->getMockBuilder('\OC\Setup') + ->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo']) + ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]) + ->getMock(); } public function testGetSupportedDatabasesWithOneWorking() { From 80c519fe89857cfead7344025f2123e3b69665a8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:24:06 +0200 Subject: [PATCH 17/22] Fix getMock Share --- tests/lib/Share/MailNotificationsTest.php | 9 ++++++--- tests/lib/Share20/ShareTest.php | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/lib/Share/MailNotificationsTest.php b/tests/lib/Share/MailNotificationsTest.php index 0c951d11f88e8..d56efe57c9df5 100644 --- a/tests/lib/Share/MailNotificationsTest.php +++ b/tests/lib/Share/MailNotificationsTest.php @@ -60,7 +60,7 @@ public function setUp() { ->disableOriginalConstructor()->getMock(); $this->user = $this->getMockBuilder('\OCP\IUser') ->disableOriginalConstructor()->getMock(); - $this->urlGenerator = $this->getMock('\OCP\IURLGenerator'); + $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10n->expects($this->any()) ->method('t') @@ -212,14 +212,17 @@ public function testSendInternalShareMail() { $this->setupMailerMock('TestUser shared »welcome.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false); /** @var MailNotifications | \PHPUnit_Framework_MockObject_MockObject $mailNotifications */ - $mailNotifications = $this->getMock('OC\Share\MailNotifications',['getItemSharedWithUser'], [ + $mailNotifications = $this->getMockBuilder(MailNotifications::class) + ->setMethods(['getItemSharedWithUser']) + ->setConstructorArgs([ $this->user, $this->l10n, $this->mailer, $this->logger, $this->defaults, $this->urlGenerator - ]); + ]) + ->getMock(); $mailNotifications->method('getItemSharedWithUser') ->withAnyParameters() diff --git a/tests/lib/Share20/ShareTest.php b/tests/lib/Share20/ShareTest.php index 91bd2fe84b637..fbdf8e5c15b13 100644 --- a/tests/lib/Share20/ShareTest.php +++ b/tests/lib/Share20/ShareTest.php @@ -21,6 +21,7 @@ namespace Test\Share20; use OCP\Files\IRootFolder; +use OCP\IUserManager; /** * Class ShareTest @@ -35,8 +36,8 @@ class ShareTest extends \Test\TestCase { protected $share; public function setUp() { - $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); - $this->userManager = $this->getMock('OCP\IUserManager'); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->userManager = $this->createMock(IUserManager::class); $this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager); } From 9d4729cb6a33bba37d246230a15eccf6ff8c3165 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:25:35 +0200 Subject: [PATCH 18/22] Fix getMock TempManagerTest --- tests/lib/TempManagerTest.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/lib/TempManagerTest.php b/tests/lib/TempManagerTest.php index d3f6ee1dc4738..23d171180fdc5 100644 --- a/tests/lib/TempManagerTest.php +++ b/tests/lib/TempManagerTest.php @@ -10,6 +10,7 @@ namespace Test; use OC\Log; +use OCP\IConfig; class NullLogger extends Log { public function __construct($logger = null) { @@ -50,7 +51,7 @@ protected function getManager($logger = null, $config = null) { $logger = new NullLogger(); } if (!$config) { - $config = $this->getMock('\OCP\IConfig'); + $config = $this->createMock(IConfig::class); $config->method('getSystemValue') ->with('tempdirectory', null) ->willReturn('/tmp'); @@ -140,7 +141,7 @@ public function testCleanOld() { public function testLogCantCreateFile() { $this->markTestSkipped('TODO: Disable because fails on drone'); - $logger = $this->getMock('\Test\NullLogger'); + $logger = $this->createMock(NullLogger::class); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); $logger->expects($this->once()) @@ -152,7 +153,7 @@ public function testLogCantCreateFile() { public function testLogCantCreateFolder() { $this->markTestSkipped('TODO: Disable because fails on drone'); - $logger = $this->getMock('\Test\NullLogger'); + $logger = $this->createMock(NullLogger::class); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); $logger->expects($this->once()) @@ -162,7 +163,7 @@ public function testLogCantCreateFolder() { } public function testBuildFileNameWithPostfix() { - $logger = $this->getMock('\Test\NullLogger'); + $logger = $this->createMock(NullLogger::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', @@ -173,7 +174,7 @@ public function testBuildFileNameWithPostfix() { } public function testBuildFileNameWithoutPostfix() { - $logger = $this->getMock('\Test\NullLogger'); + $logger = $this->createMock(NullLogger::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', @@ -184,7 +185,7 @@ public function testBuildFileNameWithoutPostfix() { } public function testBuildFileNameWithSuffixPathTraversal() { - $logger = $this->getMock('\Test\NullLogger'); + $logger = $this->createMock(NullLogger::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', @@ -198,7 +199,7 @@ public function testBuildFileNameWithSuffixPathTraversal() { public function testGetTempBaseDirFromConfig() { $dir = $this->getManager()->getTemporaryFolder(); - $config = $this->getMock('\OCP\IConfig'); + $config = $this->createMock(IConfig::class); $config->expects($this->once()) ->method('getSystemValue') ->with('tempdirectory', null) From d8a4769cd633d475e172b23636bcf93ecbdbb864 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:26:21 +0200 Subject: [PATCH 19/22] Fix getMock Template --- tests/lib/Template/ResourceLocatorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/Template/ResourceLocatorTest.php b/tests/lib/Template/ResourceLocatorTest.php index 1918b927c94de..17326f6c691f0 100644 --- a/tests/lib/Template/ResourceLocatorTest.php +++ b/tests/lib/Template/ResourceLocatorTest.php @@ -9,6 +9,7 @@ namespace Test\Template; use OC\Template\ResourceNotFoundException; +use OCP\ILogger; class ResourceLocatorTest extends \Test\TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ @@ -16,7 +17,7 @@ class ResourceLocatorTest extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->logger = $this->getMock('OCP\ILogger'); + $this->logger = $this->createMock(ILogger::class); } /** From ab797929e2b6920bd8aad19d7615e607c83306f9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:27:27 +0200 Subject: [PATCH 20/22] Fix getMock Updater --- tests/lib/Updater/VersionCheckTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index e39c9362a1463..e9b915f150853 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -41,8 +41,10 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); - $this->updater = $this->getMock('\OC\Updater\VersionCheck', - ['getUrlContent'], [$clientService, $this->config]); + $this->updater = $this->getMockBuilder(VersionCheck::class) + ->setMethods(['getUrlContent']) + ->setConstructorArgs([$clientService, $this->config]) + ->getMock(); } /** From 835daedbbc6d49f860e6f608496788e8846cc6d8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:29:27 +0200 Subject: [PATCH 21/22] Fix getMock settings --- .../Controller/AuthSettingsControllerTest.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/Settings/Controller/AuthSettingsControllerTest.php b/tests/Settings/Controller/AuthSettingsControllerTest.php index b57aea0930cfc..9cb49e4eb3f11 100644 --- a/tests/Settings/Controller/AuthSettingsControllerTest.php +++ b/tests/Settings/Controller/AuthSettingsControllerTest.php @@ -25,9 +25,15 @@ use OC\AppFramework\Http; use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\DefaultToken; +use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OC\Settings\Controller\AuthSettingsController; use OCP\AppFramework\Http\JSONResponse; +use OCP\IRequest; +use OCP\ISession; +use OCP\IUser; +use OCP\IUserManager; +use OCP\Security\ISecureRandom; use OCP\Session\Exceptions\SessionNotAvailableException; use Test\TestCase; @@ -45,13 +51,13 @@ class AuthSettingsControllerTest extends TestCase { protected function setUp() { parent::setUp(); - $this->request = $this->getMock('\OCP\IRequest'); - $this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider'); - $this->userManager = $this->getMock('\OCP\IUserManager'); - $this->session = $this->getMock('\OCP\ISession'); - $this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom'); + $this->request = $this->createMock(IRequest::class); + $this->tokenProvider = $this->createMock(IProvider::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->session = $this->createMock(ISession::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); $this->uid = 'jane'; - $this->user = $this->getMock('\OCP\IUser'); + $this->user = $this->createMock(IUser::class); $this->controller = new AuthSettingsController('core', $this->request, $this->tokenProvider, $this->userManager, $this->session, $this->secureRandom, $this->uid); } @@ -105,8 +111,8 @@ public function testIndex() { public function testCreate() { $name = 'Nexus 4'; - $sessionToken = $this->getMock('\OC\Authentication\Token\IToken'); - $deviceToken = $this->getMock('\OC\Authentication\Token\IToken'); + $sessionToken = $this->createMock(IToken::class); + $deviceToken = $this->createMock(IToken::class); $password = '123456'; $this->session->expects($this->once()) @@ -175,7 +181,7 @@ public function testCreateInvalidToken() { public function testDestroy() { $id = 123; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') From 680b557a4b906c3ef39daa2bd9e8eb1eae80a9d2 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 20:34:47 +0200 Subject: [PATCH 22/22] Fix apps warnings --- apps/encryption/tests/HookManagerTest.php | 3 ++- .../tests/Unit/Service/BackupCodeStorageTest.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/encryption/tests/HookManagerTest.php b/apps/encryption/tests/HookManagerTest.php index 1154368fa3f9d..c5e5487dba580 100644 --- a/apps/encryption/tests/HookManagerTest.php +++ b/apps/encryption/tests/HookManagerTest.php @@ -26,6 +26,7 @@ use OCA\Encryption\HookManager; +use OCP\IConfig; use Test\TestCase; class HookManagerTest extends TestCase { @@ -42,7 +43,7 @@ public function testRegisterHookWithArray() { self::$instance->registerHook([ $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(), - $this->getMock('NotIHook') + $this->createMock(IConfig::class) ]); $hookInstances = self::invokePrivate(self::$instance, 'hookInstances'); diff --git a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php index 04c51fa7e1454..57c262e1940d2 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php @@ -170,7 +170,7 @@ public function testValidateCode() { ->will($this->returnValue($codes)); $this->hasher->expects($this->once()) ->method('verify') - ->with('CHALLENGE', 'HASHEDVALUE') + ->with('CHALLENGE', 'HASHEDVALUE', $this->anything()) ->will($this->returnValue(true)); $this->mapper->expects($this->once()) ->method('update') @@ -195,7 +195,7 @@ public function testValidateUsedCode() { ->with($user) ->will($this->returnValue($codes)); $this->hasher->expects($this->never()) - ->method('verifiy'); + ->method('verify'); $this->mapper->expects($this->never()) ->method('update');