diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php index 1d12147af0d..8d3db539dd0 100644 --- a/tests/lib/Cache/FileCacheTest.php +++ b/tests/lib/Cache/FileCacheTest.php @@ -88,7 +88,7 @@ class FileCacheTest extends TestCache { private function setupMockStorage() { $mockStorage = $this->getMockBuilder(Local::class) - ->setMethods(['filemtime', 'unlink']) + ->onlyMethods(['filemtime', 'unlink']) ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]) ->getMock(); @@ -125,7 +125,7 @@ class FileCacheTest extends TestCache { $this->instance->gc(); } - public function lockExceptionProvider() { + public static function lockExceptionProvider(): array { return [ [new \OCP\Lock\LockedException('key1')], [new \OCP\Files\LockNotAcquiredException('key1', 1)], diff --git a/tests/lib/Calendar/ManagerTest.php b/tests/lib/Calendar/ManagerTest.php index cecebcfc4cf..1fb64d97f47 100644 --- a/tests/lib/Calendar/ManagerTest.php +++ b/tests/lib/Calendar/ManagerTest.php @@ -199,7 +199,7 @@ class ManagerTest extends TestCase { $this->assertEquals($expected, $result); } - public function searchProvider() { + public static function searchProvider(): array { $search1 = [ [ 'id' => 1, @@ -1096,7 +1096,7 @@ class ManagerTest extends TestCase { $this->userManager, $this->serverFactory, ]) - ->setMethods([ + ->onlyMethods([ 'getCalendarsForPrincipal' ]) ->getMock(); @@ -1544,11 +1544,11 @@ class ManagerTest extends TestCase { $this->userManager, $this->serverFactory, ]) - ->setMethods([ + ->onlyMethods([ 'getCalendarsForPrincipal' ]) ->getMock(); - + $principalUri = 'principals/user/pierre'; $sender = 'clint@stardew-tent-living.com'; $recipient = 'pierre@general-store.com'; @@ -1588,7 +1588,7 @@ class ManagerTest extends TestCase { $this->userManager, $this->serverFactory, ]) - ->setMethods([ + ->onlyMethods([ 'getCalendarsForPrincipal' ]) ->getMock(); diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php index 1ac7342a3d8..e661b0481f9 100644 --- a/tests/lib/Encryption/EncryptionWrapperTest.php +++ b/tests/lib/Encryption/EncryptionWrapperTest.php @@ -10,10 +10,13 @@ namespace Test\Encryption; use OC\Encryption\EncryptionWrapper; use OC\Encryption\Manager; use OC\Memcache\ArrayCache; +use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IStorage; use Psr\Log\LoggerInterface; use Test\TestCase; +use OCA\Files_Trashbin\Storage; +use OC\Files\Storage\Wrapper\Encryption; class EncryptionWrapperTest extends TestCase { /** @var EncryptionWrapper */ @@ -55,7 +58,7 @@ class EncryptionWrapperTest extends TestCase { ]); } - $mount = $this->getMockBuilder('OCP\Files\Mount\IMountPoint') + $mount = $this->getMockBuilder(IMountPoint::class) ->disableOriginalConstructor() ->getMock(); @@ -63,16 +66,16 @@ class EncryptionWrapperTest extends TestCase { $this->assertEquals( $expectedWrapped, - $returnedStorage->instanceOfStorage('OC\Files\Storage\Wrapper\Encryption'), + $returnedStorage->instanceOfStorage(Encryption::class), 'Asserted that the storage is (not) wrapped with encryption' ); } - public function provideWrapStorage() { + public static function provideWrapStorage(): array { return [ // Wrap when not wrapped or not wrapped with storage [true, []], - [true, ['OCA\Files_Trashbin\Storage']], + [true, [Storage::class]], // Do not wrap shared storages [false, [IDisableEncryptionStorage::class]], diff --git a/tests/lib/Encryption/UpdateTest.php b/tests/lib/Encryption/UpdateTest.php index 9940549981f..4f3de2b495d 100644 --- a/tests/lib/Encryption/UpdateTest.php +++ b/tests/lib/Encryption/UpdateTest.php @@ -113,12 +113,7 @@ class UpdateTest extends TestCase { $updateMock->update($node); } - /** - * data provider for testUpdate() - * - * @return array - */ - public function dataTestUpdate() { + public static function dataTestUpdate(): array { return [ ['/user/files/foo', true, ['/user/files/foo/file1.txt', '/user/files/foo/file1.txt'], 2], ['/user/files/test.txt', false, [], 1], @@ -152,12 +147,7 @@ class UpdateTest extends TestCase { $updateMock->postRename($sourceNode, $targetNode); } - /** - * test data for testPostRename() - * - * @return array - */ - public function dataTestPostRename() { + public static function dataTestPostRename(): array { return [ ['/test.txt', '/testNew.txt'], ['/folder/test.txt', '/testNew.txt'], @@ -193,6 +183,8 @@ class UpdateTest extends TestCase { $this->logger, $this->uid ] - )->setMethods($methods)->getMock(); + ) + ->onlyMethods($methods) + ->getMock(); } } diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 62ef809a867..68989c55fb0 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -20,7 +20,7 @@ class UtilTest extends TestCase { * * @see https://bugs.php.net/bug.php?id=21641 */ - protected int $headerSize = 8192; + protected static int $headerSize = 8192; /** @var \PHPUnit\Framework\MockObject\MockObject */ protected $view; @@ -61,7 +61,7 @@ class UtilTest extends TestCase { $this->assertEquals($expected, $id); } - public function providesHeadersForEncryptionModule() { + public static function providesHeadersForEncryptionModule(): array { return [ ['', []], ['', ['1']], @@ -80,11 +80,11 @@ class UtilTest extends TestCase { $this->assertEquals($expected, $result); } - public function providesHeaders() { + public static function providesHeaders(): array { return [ - [str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT) , [], '0'], - [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT) , ['custom_header' => 'foo'], '0'], ]; } @@ -120,7 +120,7 @@ class UtilTest extends TestCase { ); } - public function providePathsForTestIsExcluded() { + public static function providePathsForTestIsExcluded(): array { return [ ['/files_encryption', '', true], ['files_encryption/foo.txt', '', true], @@ -152,7 +152,7 @@ class UtilTest extends TestCase { ); } - public function dataTestIsFile() { + public static function dataTestIsFile(): array { return [ ['/user/files/test.txt', true], ['/user/files', true], @@ -175,7 +175,7 @@ class UtilTest extends TestCase { $this->util->stripPartialFileExtension($path)); } - public function dataTestStripPartialFileExtension() { + public static function dataTestStripPartialFileExtension(): array { return [ ['/foo/test.txt', '/foo/test.txt'], ['/foo/test.txt.part', '/foo/test.txt'], @@ -196,17 +196,17 @@ class UtilTest extends TestCase { } } - public function dataTestParseRawHeader() { + public static function dataTestParseRawHeader(): array { return [ - [str_pad('HBEGIN:oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('HBEGIN:oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT) , [Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], - [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('HBEGIN:oc_encryption_module:0:custom_header:foo:HEND', self::$headerSize, '-', STR_PAD_RIGHT) , ['custom_header' => 'foo', Util::HEADER_ENCRYPTION_MODULE_KEY => '0']], - [str_pad('HelloWorld', $this->headerSize, '-', STR_PAD_RIGHT), []], + [str_pad('HelloWorld', self::$headerSize, '-', STR_PAD_RIGHT), []], ['', []], - [str_pad('HBEGIN:oc_encryption_module:0', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('HBEGIN:oc_encryption_module:0', self::$headerSize, '-', STR_PAD_RIGHT) , []], - [str_pad('oc_encryption_module:0:HEND', $this->headerSize, '-', STR_PAD_RIGHT) + [str_pad('oc_encryption_module:0:HEND', self::$headerSize, '-', STR_PAD_RIGHT) , []], ]; } @@ -245,7 +245,7 @@ class UtilTest extends TestCase { ); } - public function dataTestGetFileKeyDir() { + public static function dataTestGetFileKeyDir(): array { return [ [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], diff --git a/tests/lib/GlobalScale/ConfigTest.php b/tests/lib/GlobalScale/ConfigTest.php index aa001268ecd..b6c77c9ddf1 100644 --- a/tests/lib/GlobalScale/ConfigTest.php +++ b/tests/lib/GlobalScale/ConfigTest.php @@ -28,7 +28,7 @@ class ConfigTest extends TestCase { if (!empty($mockMethods)) { return $this->getMockBuilder(Config::class) ->setConstructorArgs([$this->config]) - ->setMethods($mockMethods) + ->onlyMethods($mockMethods) ->getMock(); } @@ -64,7 +64,7 @@ class ConfigTest extends TestCase { $this->assertSame($expected, $gsConfig->onlyInternalFederation()); } - public function dataTestOnlyInternalFederation() { + public static function dataTestOnlyInternalFederation(): array { return [ [true, 'global', false], [true, 'internal', true], diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index 0f8d7a5ecc3..e52e0733501 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -12,6 +12,11 @@ use OC\Group\Database; use OC\User\Manager; use OC\User\User; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Group\Backend\ABackend; +use OCP\Group\Backend\IAddToGroupBackend; +use OCP\Group\Backend\ICreateGroupBackend; +use OCP\Group\Backend\IGroupDetailsBackend; +use OCP\Group\Backend\IRemoveFromGroupBackend; use OCP\Group\Backend\ISearchableGroupBackend; use OCP\GroupInterface; use OCP\ICacheFactory; @@ -21,7 +26,8 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; -interface ISearchableGroupInterface extends ISearchableGroupBackend, GroupInterface { +abstract class TestBackend extends ABackend implements ISearchableGroupBackend, IAddToGroupBackend, ICreateGroupBackend, IGroupDetailsBackend, IRemoveFromGroupBackend, GroupInterface { + } class ManagerTest extends TestCase { @@ -74,9 +80,9 @@ class ManagerTest extends TestCase { } // need to declare it this way due to optional methods // thanks to the implementsActions logic - $backend = $this->getMockBuilder(ISearchableGroupInterface::class) + $backend = $this->getMockBuilder(TestBackend::class) ->disableOriginalConstructor() - ->setMethods([ + ->onlyMethods([ 'getGroupDetails', 'implementsActions', 'getUserGroups', @@ -283,9 +289,10 @@ class ManagerTest extends TestCase { ->with('1') ->willReturn(['group1']); $backend->expects($this->once()) - ->method('groupExists') - ->with('group1') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnMap([ + ['group1', ['displayName' => 'group1']], + ]); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend); @@ -306,8 +313,11 @@ class ManagerTest extends TestCase { ->with('1') ->willReturn(['group1']); $backend1->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnMap([ + ['group1', ['displayName' => 'group1']], + ['group12', []], + ]); /** * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2 @@ -318,8 +328,11 @@ class ManagerTest extends TestCase { ->with('1') ->willReturn(['group12', 'group1']); $backend2->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnMap([ + ['group12', ['displayName' => 'group12']], + ['group1', ['displayName' => 'group1']], + ]); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend1); @@ -335,7 +348,7 @@ class ManagerTest extends TestCase { public function testSearchMultipleBackendsLimitAndOffset(): void { /** - * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend1 */ $backend1 = $this->getTestBackend(); $backend1->expects($this->once()) @@ -343,11 +356,16 @@ class ManagerTest extends TestCase { ->with('1', 2, 1) ->willReturn(['group1']); $backend1->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnMap([ + [1, []], + [2, []], + ['group1', ['displayName' => 'group1']], + ['group12', []], + ]); /** - * @var \PHPUnit\Framework\MockObject\MockObject | \OC\Group\Backend $backend2 + * @var \PHPUnit\Framework\MockObject\MockObject|\OC\Group\Backend $backend2 */ $backend2 = $this->getTestBackend(); $backend2->expects($this->once()) @@ -355,8 +373,13 @@ class ManagerTest extends TestCase { ->with('1', 2, 1) ->willReturn(['group12']); $backend2->expects($this->any()) - ->method('groupExists') - ->willReturn(true); + ->method('getGroupDetails') + ->willReturnMap([ + [1, []], + [2, []], + ['group1', []], + ['group12', ['displayName' => 'group12']], + ]); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger, $this->cache, $this->remoteIpAddress); $manager->addBackend($backend1);