]> source.dussan.org Git - nextcloud-server.git/commitdiff
File getMock Files tests
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 7 Sep 2016 18:01:13 +0000 (20:01 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 7 Sep 2016 18:42:37 +0000 (20:42 +0200)
tests/lib/Files/Mount/MountPointTest.php
tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
tests/lib/Files/ObjectStore/MapperTest.php
tests/lib/Files/Storage/Wrapper/EncryptionTest.php
tests/lib/Files/Stream/EncryptionTest.php

index 799f441a1aba661be84c4cc650f6cb362315a9d3..03b106eb598bc7b6b552ca1552f9f8a8cccdcd45 100644 (file)
@@ -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 @@ class MountPointTest extends \Test\TestCase {
        }
 
        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')));
index 5d987f0d059fec63842f9ae2a97fc7adeb45d692..0af90991d60ffeb98dbe5649926d81deead17b95 100644 (file)
@@ -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 @@ class FakeObjectStore {
        public function getArguments() {
                return $this->arguments;
        }
-}
\ No newline at end of file
+}
index 1ebb67a6905a07e7de3dd3ef8344ec38f6694d8f..18bdcdfd0055cc06f26cccbe27d2527efbbca242 100644 (file)
@@ -22,6 +22,7 @@ namespace Test\Files\ObjectStore;
 
 
 use OC\Files\ObjectStore\Mapper;
+use OCP\IUser;
 
 class MapperTest extends \Test\TestCase {
 
@@ -39,7 +40,7 @@ class MapperTest extends \Test\TestCase {
         * @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 @@ class MapperTest extends \Test\TestCase {
 
                $this->assertSame($expectedBucket, $mapper->getBucket());
        }
-}
\ No newline at end of file
+}
index e9ebf2f3bdfbac93f45dd6067c2dbb78ba29b99c..55b38d546decc0fab62d85b32aa723884db15e23 100644 (file)
@@ -5,7 +5,10 @@ namespace Test\Files\Storage\Wrapper;
 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 @@ class EncryptionTest extends Storage {
                        ->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 @@ class EncryptionTest extends Storage {
                        ->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 @@ class EncryptionTest extends Storage {
                        ->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 @@ class EncryptionTest extends Storage {
                                $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 @@ class EncryptionTest extends Storage {
                                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)
index 45204e48d09a7df801d52a5d213213f38c85d5ac..6f3c879f9e6fbe8e618f0cff40fab2bc087339e0 100644 (file)
@@ -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 @@ class EncryptionTest extends \Test\TestCase {
                $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 @@ class EncryptionTest extends \Test\TestCase {
                        ->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]);