diff options
author | Joas Schilling <coding@schilljs.com> | 2025-05-13 09:46:15 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2025-05-15 08:25:00 +0200 |
commit | 9621e451ba24c287b4bab73d4376a6655f59cd7f (patch) | |
tree | a38fe0709c9a6b3846ab4925ffc76b72ca8fe475 /tests | |
parent | e0a1c84ebb6909015ec9143d66ded830e6abe81b (diff) | |
download | nextcloud-server-9621e451ba24c287b4bab73d4376a6655f59cd7f.tar.gz nextcloud-server-9621e451ba24c287b4bab73d4376a6655f59cd7f.zip |
test: Fix tests/lib/Files
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Config/UserConfigTest.php | 69 | ||||
-rw-r--r-- | tests/lib/ErrorHandlerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 50 | ||||
-rw-r--r-- | tests/lib/Files/Cache/ScannerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Cache/SearchBuilderTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Cache/UpdaterTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 23 | ||||
-rw-r--r-- | tests/lib/Files/Stream/EncryptionTest.php | 44 | ||||
-rw-r--r-- | tests/lib/Files/Stream/HashWrapperTest.php | 2 |
10 files changed, 95 insertions, 103 deletions
diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php index f9a9b5c5272..7bd1e06e297 100644 --- a/tests/lib/Config/UserConfigTest.php +++ b/tests/lib/Config/UserConfigTest.php @@ -333,10 +333,7 @@ class UserConfigTest extends TestCase { ); } - /** - * @return array[] - */ - public function providerHasKey(): array { + public static function providerHasKey(): array { return [ ['user1', 'app1', 'key1', false, true], ['user0', 'app1', 'key1', false, false], @@ -358,10 +355,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->hasKey($userId, $appId, $key, $lazy)); } - /** - * @return array[] - */ - public function providerIsSensitive(): array { + public static function providerIsSensitive(): array { return [ ['user1', 'app1', 'key1', false, false, false], ['user0', 'app1', 'key1', false, false, true], @@ -399,10 +393,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->isSensitive($userId, $appId, $key, $lazy)); } - /** - * @return array[] - */ - public function providerIsLazy(): array { + public static function providerIsLazy(): array { return [ ['user1', 'app1', 'key1', false, false], ['user0', 'app1', 'key1', false, true], @@ -432,7 +423,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->isLazy($userId, $appId, $key)); } - public function providerGetValues(): array { + public static function providerGetValues(): array { return [ [ 'user1', 'app1', '', true, @@ -565,7 +556,7 @@ class UserConfigTest extends TestCase { ); } - public function providerGetAllValues(): array { + public static function providerGetAllValues(): array { return [ [ 'user2', false, @@ -662,7 +653,7 @@ class UserConfigTest extends TestCase { $this->assertEqualsCanonicalizing($result, $userConfig->getAllValues($userId, $filtered)); } - public function providerSearchValuesByApps(): array { + public static function providerSearchValuesByApps(): array { return [ [ 'user1', 'key1', false, null, @@ -708,7 +699,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->getValuesByApps($userId, $key, $lazy, $typedAs)); } - public function providerSearchValuesByUsers(): array { + public static function providerSearchValuesByUsers(): array { return [ [ 'app2', 'key2', null, null, @@ -760,7 +751,7 @@ class UserConfigTest extends TestCase { ); } - public function providerSearchValuesByValueString(): array { + public static function providerSearchValuesByValueString(): array { return [ ['app2', 'key2', 'value2a', false, ['user1']], ['app2', 'key2', 'value2A', false, ['user4']], @@ -782,7 +773,7 @@ class UserConfigTest extends TestCase { $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueString($app, $key, $value, $ci))); } - public function providerSearchValuesByValueInt(): array { + public static function providerSearchValuesByValueInt(): array { return [ ['app3', 'key8', 12, []], // sensitive value, cannot search ['app2', 'key8', 12, ['user2', 'user5']], // sensitive value, cannot search @@ -803,7 +794,7 @@ class UserConfigTest extends TestCase { $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueInt($app, $key, $value))); } - public function providerSearchValuesByValues(): array { + public static function providerSearchValuesByValues(): array { return [ ['app2', 'key2', ['value2a', 'value2b'], ['user1', 'user2']], ['app2', 'key2', ['value2a', 'value2c'], ['user1', 'user3']], @@ -823,7 +814,7 @@ class UserConfigTest extends TestCase { $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValues($app, $key, $values))); } - public function providerSearchValuesByValueBool(): array { + public static function providerSearchValuesByValueBool(): array { return [ ['app3', 'key10', true, ['user1', 'user4']], ['app3', 'key10', false, ['user2']], @@ -843,7 +834,7 @@ class UserConfigTest extends TestCase { $this->assertEqualsCanonicalizing($result, iterator_to_array($userConfig->searchUsersByValueBool($app, $key, $value))); } - public function providerGetValueMixed(): array { + public static function providerGetValueMixed(): array { return [ [ ['user1'], 'user1', 'app1', 'key0', 'default_because_unknown_key', true, @@ -943,7 +934,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->getValueString($userId, $app, $key, $default, $lazy)); } - public function providerGetValueInt(): array { + public static function providerGetValueInt(): array { return [ [['user1'], 'user1', 'app1', 'key0', 54321, true, 54321], [null, 'user1', 'app1', 'key0', 54321, true, 54321], @@ -985,7 +976,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->getValueInt($userId, $app, $key, $default, $lazy)); } - public function providerGetValueFloat(): array { + public static function providerGetValueFloat(): array { return [ [['user1'], 'user1', 'app1', 'key0', 54.321, true, 54.321], [null, 'user1', 'app1', 'key0', 54.321, true, 54.321], @@ -1026,7 +1017,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->getValueFloat($userId, $app, $key, $default, $lazy)); } - public function providerGetValueBool(): array { + public static function providerGetValueBool(): array { return [ [['user1'], 'user1', 'app1', 'key0', false, true, false], [null, 'user1', 'app1', 'key0', false, true, false], @@ -1087,7 +1078,7 @@ class UserConfigTest extends TestCase { $this->assertEquals($result, $userConfig->getValueBool($userId, $app, $key, $default, $lazy)); } - public function providerGetValueArray(): array { + public static function providerGetValueArray(): array { return [ [ ['user1'], 'user1', 'app1', 'key0', ['default_because_unknown_key'], true, @@ -1126,7 +1117,7 @@ class UserConfigTest extends TestCase { ); } - public function providerGetValueType(): array { + public static function providerGetValueType(): array { return [ [null, 'user1', 'app1', 'key1', false, ValueType::MIXED], [null, 'user1', 'app1', 'key1', true, null, UnknownKeyException::class], @@ -1187,7 +1178,7 @@ class UserConfigTest extends TestCase { } } - public function providerSetValueMixed(): array { + public static function providerSetValueMixed(): array { return [ [null, 'user1', 'app1', 'key1', 'value', false, false, true], [null, 'user1', 'app1', 'key1', '12345', true, false, true], @@ -1250,7 +1241,7 @@ class UserConfigTest extends TestCase { } - public function providerSetValueString(): array { + public static function providerSetValueString(): array { return [ [null, 'user1', 'app1', 'key1', 'value', false, false, true], [null, 'user1', 'app1', 'key1', '12345', true, false, true], @@ -1325,7 +1316,7 @@ class UserConfigTest extends TestCase { } } - public function providerSetValueInt(): array { + public static function providerSetValueInt(): array { return [ [null, 'user1', 'app1', 'key1', 12345, false, false, true], [null, 'user1', 'app1', 'key1', 12345, true, false, true], @@ -1389,7 +1380,7 @@ class UserConfigTest extends TestCase { } } - public function providerSetValueFloat(): array { + public static function providerSetValueFloat(): array { return [ [null, 'user1', 'app1', 'key1', 12.345, false, false, true], [null, 'user1', 'app1', 'key1', 12.345, true, false, true], @@ -1453,7 +1444,7 @@ class UserConfigTest extends TestCase { } - public function providerSetValueArray(): array { + public static function providerSetValueArray(): array { return [ [null, 'user1', 'app1', 'key1', [], false, false, true], [null, 'user1', 'app1', 'key1', [], true, false, true], @@ -1520,7 +1511,7 @@ class UserConfigTest extends TestCase { } } - public function providerUpdateSensitive(): array { + public static function providerUpdateSensitive(): array { return [ [null, 'user1', 'app1', 'key1', false, false], [['user1'], 'user1', 'app1', 'key1', false, false], @@ -1566,7 +1557,7 @@ class UserConfigTest extends TestCase { } } - public function providerUpdateGlobalSensitive(): array { + public static function providerUpdateGlobalSensitive(): array { return [[true], [false]]; } @@ -1610,7 +1601,7 @@ class UserConfigTest extends TestCase { } } - public function providerUpdateLazy(): array { + public static function providerUpdateLazy(): array { return [ [null, 'user1', 'app1', 'key1', false, false], [['user1'], 'user1', 'app1', 'key1', false, false], @@ -1649,7 +1640,7 @@ class UserConfigTest extends TestCase { } } - public function providerUpdateGlobalLazy(): array { + public static function providerUpdateGlobalLazy(): array { return [[true], [false]]; } @@ -1679,7 +1670,7 @@ class UserConfigTest extends TestCase { } } - public function providerGetDetails(): array { + public static function providerGetDetails(): array { return [ [ 'user3', 'app2', 'key2', @@ -1732,7 +1723,7 @@ class UserConfigTest extends TestCase { } - public function providerDeletePreference(): array { + public static function providerDeletePreference(): array { return [ [null, 'user1', 'app1', 'key22'], [['user1'], 'user1', 'app1', 'fast_string_sensitive'], @@ -1763,7 +1754,7 @@ class UserConfigTest extends TestCase { $this->assertEquals(false, $userConfig->hasKey($userId, $app, $key, $lazy)); } - public function providerDeleteKey(): array { + public static function providerDeleteKey(): array { return [ [null, 'app2', 'key3'], [['user1'], 'app2', 'key3'], @@ -1832,7 +1823,7 @@ class UserConfigTest extends TestCase { 'fastCache' => [], 'lazyLoaded' => [], 'lazyCache' => [], - 'valueTypes' => [], + 'valueDetails' => [], ], $userConfig->statusCache() ); diff --git a/tests/lib/ErrorHandlerTest.php b/tests/lib/ErrorHandlerTest.php index b45525e7962..a2003cfbd93 100644 --- a/tests/lib/ErrorHandlerTest.php +++ b/tests/lib/ErrorHandlerTest.php @@ -34,7 +34,7 @@ class ErrorHandlerTest extends TestCase { * provide username, password combinations for testRemovePassword * @return array */ - public function passwordProvider() { + public static function passwordProvider(): array { return [ ['us:er', 'pass@word'], ['us:er', 'password'], diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 204f87d6a18..55b210a1e2d 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -49,6 +49,25 @@ class CacheTest extends \Test\TestCase { */ protected $cache2; + protected function setUp(): void { + parent::setUp(); + + $this->storage = new \OC\Files\Storage\Temporary([]); + $this->storage2 = new \OC\Files\Storage\Temporary([]); + $this->cache = new \OC\Files\Cache\Cache($this->storage); + $this->cache2 = new \OC\Files\Cache\Cache($this->storage2); + $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); + } + + protected function tearDown(): void { + if ($this->cache) { + $this->cache->clear(); + } + + parent::tearDown(); + } + public function testGetNumericId(): void { $this->assertNotNull($this->cache->getNumericStorageId()); } @@ -208,7 +227,7 @@ class CacheTest extends \Test\TestCase { } } - public function folderDataProvider() { + public static function folderDataProvider(): array { return [ ['folder'], // that was too easy, try something harder @@ -301,7 +320,7 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo')); } - public function putWithAllKindOfQuotesData() { + public static function putWithAllKindOfQuotesData(): array { return [ ['`backtick`'], ['´forward´'], @@ -437,7 +456,7 @@ class CacheTest extends \Test\TestCase { new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100), 10, 0, [], $user))); } - public function movePathProvider() { + public static function movePathProvider(): array { return [ ['folder/foo', 'folder/foobar', ['1', '2']], ['folder/foo', 'foo', ['1', '2']], @@ -575,7 +594,7 @@ class CacheTest extends \Test\TestCase { * @var \OC\Files\Cache\Cache | \PHPUnit\Framework\MockObject\MockObject $cacheMock */ $cacheMock = $this->getMockBuilder(Cache::class) - ->setMethods(['normalize']) + ->onlyMethods(['normalize']) ->setConstructorArgs([$this->storage]) ->getMock(); @@ -646,7 +665,7 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(1, count($this->cache->getFolderContents('folder'))); } - public function bogusPathNamesProvider() { + public static function bogusPathNamesProvider(): array { return [ ['/bogus.txt', 'bogus.txt'], ['//bogus.txt', 'bogus.txt'], @@ -691,7 +710,7 @@ class CacheTest extends \Test\TestCase { $this->assertNotEquals($fileId, $fileId2); } - public function escapingProvider() { + public static function escapingProvider(): array { return [ ['foo'], ['o%'], @@ -807,23 +826,4 @@ class CacheTest extends \Test\TestCase { $this->cache->remove('sub'); } - - protected function tearDown(): void { - if ($this->cache) { - $this->cache->clear(); - } - - parent::tearDown(); - } - - protected function setUp(): void { - parent::setUp(); - - $this->storage = new \OC\Files\Storage\Temporary([]); - $this->storage2 = new \OC\Files\Storage\Temporary([]); - $this->cache = new \OC\Files\Cache\Cache($this->storage); - $this->cache2 = new \OC\Files\Cache\Cache($this->storage2); - $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); - $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]); - } } diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index d78b7100d43..dc5ba5d3cdf 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -394,7 +394,7 @@ class ScannerTest extends TestCase { ); } - public function dataTestIsPartialFile() { + public static function dataTestIsPartialFile(): array { return [ ['foo.txt.part', true], ['/sub/folder/foo.txt.part', true], diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php index 17285d44209..28af199639a 100644 --- a/tests/lib/Files/Cache/SearchBuilderTest.php +++ b/tests/lib/Files/Cache/SearchBuilderTest.php @@ -134,7 +134,7 @@ class SearchBuilderTest extends TestCase { return $rows; } - public function comparisonProvider() { + public static function comparisonProvider(): array { return [ [new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1]], [new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [0]], diff --git a/tests/lib/Files/Cache/UpdaterTest.php b/tests/lib/Files/Cache/UpdaterTest.php index ab46bdd4141..bc4b39a5dc4 100644 --- a/tests/lib/Files/Cache/UpdaterTest.php +++ b/tests/lib/Files/Cache/UpdaterTest.php @@ -305,7 +305,7 @@ class UpdaterTest extends \Test\TestCase { } } - public function changeExtensionProvider(): array { + public static function changeExtensionProvider(): array { return [ [new Temporary()], [new ObjectStoreStorage(['objectstore' => new StorageObjectStore(new Temporary())])] diff --git a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php index afb5c6a5d4d..9aa1ee5b723 100644 --- a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php +++ b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php @@ -34,7 +34,7 @@ class CachePermissionsMaskTest extends CacheTest { return new \OC\Files\Cache\Wrapper\CachePermissionsMask($this->sourceCache, $mask); } - public function maskProvider() { + public static function maskProvider(): array { return [ [Constants::PERMISSION_ALL], [Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE], diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 1efc56c1908..88b8b7767dd 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -9,6 +9,7 @@ namespace Test\Files\Config; use OC\DB\Exceptions\DbalException; use OC\DB\QueryBuilder\Literal; +use OC\Files\Cache\Cache; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Storage; use OC\User\Manager; @@ -88,25 +89,19 @@ class UserMountCacheTest extends TestCase { private function getStorage($storageId, $rootInternalPath = '') { $rootId = $this->createCacheEntry($rootInternalPath, $storageId); - $storageCache = $this->getMockBuilder('\OC\Files\Cache\Storage') - ->disableOriginalConstructor() - ->getMock(); + $storageCache = $this->createMock(\OC\Files\Cache\Storage::class); $storageCache->expects($this->any()) ->method('getNumericId') ->willReturn($storageId); - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') - ->disableOriginalConstructor() - ->getMock(); + $cache = $this->createMock(Cache::class); $cache->expects($this->any()) ->method('getId') ->willReturn($rootId); $cache->method('getNumericStorageId') ->willReturn($storageId); - $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor() - ->getMock(); + $storage = $this->createMock(Storage::class); $storage->expects($this->any()) ->method('getStorageCache') ->willReturn($storageCache); @@ -427,9 +422,9 @@ class UserMountCacheTest extends TestCase { $fileId = $this->createCacheEntry('/foo/bar', 2); - $mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint') + $mount1 = $this->getMockBuilder(MountPoint::class) ->setConstructorArgs([$storage1, '/']) - ->setMethods(['getStorageRootId']) + ->onlyMethods(['getStorageRootId']) ->getMock(); $mount1->expects($this->any()) @@ -460,9 +455,9 @@ class UserMountCacheTest extends TestCase { $folderId = $this->createCacheEntry('/foo', 2); $fileId = $this->createCacheEntry('/bar/asd', 2); - $mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint') + $mount1 = $this->getMockBuilder(MountPoint::class) ->setConstructorArgs([$storage1, '/foo/']) - ->setMethods(['getStorageRootId']) + ->onlyMethods(['getStorageRootId']) ->getMock(); $mount1->expects($this->any()) @@ -509,7 +504,7 @@ class UserMountCacheTest extends TestCase { $mount1 = $this->getMockBuilder(MountPoint::class) ->setConstructorArgs([$storage1, '/u1/']) - ->setMethods(['getStorageRootId', 'getNumericStorageId']) + ->onlyMethods(['getStorageRootId', 'getNumericStorageId']) ->getMock(); $mount1->expects($this->any()) diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 36e72ea764a..f51a6d3cb4e 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -9,7 +9,9 @@ declare(strict_types=1); */ namespace Test\Files\Stream; +use OC\Encryption\File; use OC\Files\Cache\CacheEntry; +use OC\Files\Storage\Storage; use OC\Files\Storage\Wrapper\Wrapper; use OC\Files\View; use OC\Memcache\ArrayCache; @@ -20,6 +22,8 @@ use OCP\ICacheFactory; use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; +use OC\Files\Stream\Encryption; +use OC\Encryption\Util; class EncryptionTest extends \Test\TestCase { public const DEFAULT_WRAPPER = '\OC\Files\Stream\Encryption'; @@ -53,11 +57,11 @@ class EncryptionTest extends \Test\TestCase { ->getMock(); $file = $this->getMockBuilder('\OC\Encryption\File') ->disableOriginalConstructor() - ->setMethods(['getAccessList']) + ->onlyMethods(['getAccessList']) ->getMock(); $file->expects($this->any())->method('getAccessList')->willReturn([]); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setMethods(['getUidAndFilename']) + ->onlyMethods(['getUidAndFilename']) ->setConstructorArgs([new View(), new \OC\User\Manager( $config, $this->createMock(ICacheFactory::class), @@ -111,20 +115,17 @@ class EncryptionTest extends \Test\TestCase { $expectedReadOnly, ): void { // build mocks - $encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') - ->disableOriginalConstructor()->getMock(); + $encryptionModuleMock = $this->createMock(IEncryptionModule::class); $encryptionModuleMock->expects($this->any())->method('needDetailedAccessList')->willReturn(!$isMasterKeyUsed); $encryptionModuleMock->expects($this->once()) ->method('getUnencryptedBlockSize')->willReturn(99); $encryptionModuleMock->expects($this->once()) ->method('begin')->willReturn([]); - $storageMock = $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor()->getMock(); + $storageMock = $this->createMock(Storage::class); $storageMock->expects($this->once())->method('file_exists')->willReturn($fileExists); - $fileMock = $this->getMockBuilder('\OC\Encryption\File') - ->disableOriginalConstructor()->getMock(); + $fileMock = $this->createMock(File::class); if ($isMasterKeyUsed) { $fileMock->expects($this->never())->method('getAccessList'); } else { @@ -134,18 +135,20 @@ class EncryptionTest extends \Test\TestCase { return []; }); } - $utilMock = $this->getMockBuilder('\OC\Encryption\Util') + $utilMock = $this->getMockBuilder(Util::class) ->disableOriginalConstructor()->getMock(); $utilMock->expects($this->any()) ->method('getHeaderSize') ->willReturn(8192); // get a instance of the stream wrapper - $streamWrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption') - ->setMethods(['loadContext', 'writeHeader', 'skipHeader'])->disableOriginalConstructor()->getMock(); + $streamWrapper = $this->getMockBuilder(Encryption::class) + ->onlyMethods(['loadContext', 'writeHeader', 'skipHeader']) + ->disableOriginalConstructor() + ->getMock(); // set internal properties of the stream wrapper - $stream = new \ReflectionClass('\OC\Files\Stream\Encryption'); + $stream = new \ReflectionClass(Encryption::class); $encryptionModule = $stream->getProperty('encryptionModule'); $encryptionModule->setAccessible(true); $encryptionModule->setValue($streamWrapper, $encryptionModuleMock); @@ -195,7 +198,7 @@ class EncryptionTest extends \Test\TestCase { $readOnly->setAccessible(false); } - public function dataProviderStreamOpen() { + public static function dataProviderStreamOpen(): array { return [ [false, 'r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true], [false, 'r', '/foo/bar/test.txt', false, '/foo/bar', null, null, true], @@ -266,7 +269,7 @@ class EncryptionTest extends \Test\TestCase { unlink($fileName); } - public function dataFilesProvider() { + public static function dataFilesProvider(): array { return [ ['lorem-big.txt'], ['block-aligned.txt'], @@ -315,9 +318,12 @@ class EncryptionTest extends \Test\TestCase { * @dataProvider dataFilesProvider */ public function testWriteToNonSeekableStorage($testFile): void { - $wrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption') - ->setMethods(['parentSeekStream'])->getMock(); - $wrapper->expects($this->any())->method('parentSeekStream')->willReturn(false); + $wrapper = $this->getMockBuilder(Encryption::class) + ->onlyMethods(['parentStreamSeek']) + ->getMock(); + $wrapper->expects($this->any()) + ->method('parentStreamSeek') + ->willReturn(false); $expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile); // write it @@ -351,9 +357,9 @@ class EncryptionTest extends \Test\TestCase { } protected function buildMockModule(): IEncryptionModule&MockObject { - $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') + $encryptionModule = $this->getMockBuilder(IEncryptionModule::class) ->disableOriginalConstructor() - ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList']) + ->onlyMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList']) ->getMock(); $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); diff --git a/tests/lib/Files/Stream/HashWrapperTest.php b/tests/lib/Files/Stream/HashWrapperTest.php index ee50fe3b13a..1e9bbd8f289 100644 --- a/tests/lib/Files/Stream/HashWrapperTest.php +++ b/tests/lib/Files/Stream/HashWrapperTest.php @@ -31,7 +31,7 @@ class HashWrapperTest extends TestCase { stream_get_contents($wrapper); } - public function hashProvider() { + public static function hashProvider(): array { return [ ['foo', 'md5', 'acbd18db4cc2f85cedef654fccc4a4d8'], ['foo', 'sha1', '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'], |