diff --git a/apps/federatedfilesharing/tests/AddressHandlerTest.php b/apps/federatedfilesharing/tests/AddressHandlerTest.php index ffb34d965ceac..232ac21a86967 100644 --- a/apps/federatedfilesharing/tests/AddressHandlerTest.php +++ b/apps/federatedfilesharing/tests/AddressHandlerTest.php @@ -1,5 +1,6 @@ urlGenerator = $this->getMockBuilder(IURLGenerator::class) - ->getMock(); - $this->il10n = $this->getMockBuilder(IL10N::class) - ->getMock(); - + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->il10n = $this->createMock(IL10N::class); $this->contactsManager = $this->createMock(IManager::class); $this->cloudIdManager = new CloudIdManager( @@ -54,7 +44,7 @@ protected function setUp(): void { $this->addressHandler = new AddressHandler($this->urlGenerator, $this->il10n, $this->cloudIdManager); } - public function dataTestSplitUserRemote() { + public static function dataTestSplitUserRemote(): array { $userPrefix = ['user@name', 'username']; $protocols = ['', 'http://', 'https://']; $remotes = [ @@ -92,12 +82,8 @@ public function dataTestSplitUserRemote() { /** * @dataProvider dataTestSplitUserRemote - * - * @param string $remote - * @param string $expectedUser - * @param string $expectedUrl */ - public function testSplitUserRemote($remote, $expectedUser, $expectedUrl): void { + public function testSplitUserRemote(string $remote, string $expectedUser, string $expectedUrl): void { $this->contactsManager->expects($this->any()) ->method('search') ->willReturn([]); @@ -107,7 +93,7 @@ public function testSplitUserRemote($remote, $expectedUser, $expectedUrl): void $this->assertSame($expectedUrl, $remoteUrl); } - public function dataTestSplitUserRemoteError() { + public static function dataTestSplitUserRemoteError(): array { return [ // Invalid path ['user@'], @@ -127,10 +113,8 @@ public function dataTestSplitUserRemoteError() { /** * @dataProvider dataTestSplitUserRemoteError - * - * @param string $id */ - public function testSplitUserRemoteError($id): void { + public function testSplitUserRemoteError(string $id): void { $this->expectException(HintException::class); $this->addressHandler->splitUserRemote($id); @@ -138,20 +122,14 @@ public function testSplitUserRemoteError($id): void { /** * @dataProvider dataTestCompareAddresses - * - * @param string $user1 - * @param string $server1 - * @param string $user2 - * @param string $server2 - * @param bool $expected */ - public function testCompareAddresses($user1, $server1, $user2, $server2, $expected): void { + public function testCompareAddresses(string $user1, string $server1, string $user2, string $server2, bool $expected): void { $this->assertSame($expected, $this->addressHandler->compareAddresses($user1, $server1, $user2, $server2) ); } - public function dataTestCompareAddresses() { + public static function dataTestCompareAddresses(): array { return [ ['user1', 'http://server1', 'user1', 'http://server1', true], ['user1', 'https://server1', 'user1', 'http://server1', true], @@ -173,35 +151,29 @@ public function dataTestCompareAddresses() { /** * @dataProvider dataTestRemoveProtocolFromUrl - * - * @param string $url - * @param string $expectedResult */ - public function testRemoveProtocolFromUrl($url, $expectedResult): void { + public function testRemoveProtocolFromUrl(string $url, string $expectedResult): void { $result = $this->addressHandler->removeProtocolFromUrl($url); $this->assertSame($expectedResult, $result); } - public function dataTestRemoveProtocolFromUrl() { + public static function dataTestRemoveProtocolFromUrl(): array { return [ - ['http://owncloud.org', 'owncloud.org'], - ['https://owncloud.org', 'owncloud.org'], - ['owncloud.org', 'owncloud.org'], + ['http://example.tld', 'example.tld'], + ['https://example.tld', 'example.tld'], + ['example.tld', 'example.tld'], ]; } /** * @dataProvider dataTestUrlContainProtocol - * - * @param string $url - * @param bool $expectedResult */ - public function testUrlContainProtocol($url, $expectedResult): void { + public function testUrlContainProtocol(string $url, bool $expectedResult): void { $result = $this->addressHandler->urlContainProtocol($url); $this->assertSame($expectedResult, $result); } - public function dataTestUrlContainProtocol() { + public static function dataTestUrlContainProtocol(): array { return [ ['http://nextcloud.com', true], ['https://nextcloud.com', true], diff --git a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php index 8222f25bb49de..a6c1014842538 100644 --- a/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php +++ b/apps/federatedfilesharing/tests/Controller/MountPublicLinkControllerTest.php @@ -1,4 +1,6 @@ request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock(); - $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') - ->disableOriginalConstructor()->getMock(); - $this->shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock(); - $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler') - ->disableOriginalConstructor()->getMock(); - $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->disableOriginalConstructor()->getMock(); - $this->userManager = $this->getMockBuilder(IUserManager::class)->disableOriginalConstructor()->getMock(); + $this->request = $this->createMock(IRequest::class); + $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class); + $this->shareManager = $this->createMock(IManager::class); + $this->addressHandler = $this->createMock(AddressHandler::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->userManager = $this->createMock(IUserManager::class); $this->share = new Share($this->rootFolder, $this->userManager); - $this->session = $this->getMockBuilder(ISession::class)->disableOriginalConstructor()->getMock(); - $this->l10n = $this->getMockBuilder(IL10N::class)->disableOriginalConstructor()->getMock(); - $this->userSession = $this->getMockBuilder(IUserSession::class)->disableOriginalConstructor()->getMock(); - $this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock(); + $this->session = $this->createMock(ISession::class); + $this->l10n = $this->createMock(IL10N::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->clientService = $this->createMock(IClientService::class); $this->contactsManager = $this->createMock(IContactsManager::class); $this->cloudIdManager = new CloudIdManager( $this->contactsManager, @@ -114,23 +87,16 @@ protected function setUp(): void { /** * @dataProvider dataTestCreateFederatedShare - * - * @param string $shareWith - * @param bool $outgoingSharesAllowed - * @param bool $validShareWith - * @param string $token - * @param bool $validToken - * @param bool $createSuccessful - * @param string $expectedReturnData */ - public function testCreateFederatedShare($shareWith, - $outgoingSharesAllowed, - $validShareWith, - $token, - $validToken, - $createSuccessful, - $expectedReturnData, - $permissions, + public function testCreateFederatedShare( + string $shareWith, + bool $outgoingSharesAllowed, + bool $validShareWith, + string $token, + bool $validToken, + bool $createSuccessful, + string $expectedReturnData, + int $permissions, ): void { $this->federatedShareProvider->expects($this->any()) ->method('isOutgoingServer2serverShareEnabled') @@ -188,7 +154,7 @@ function (IShare $share) use ($createSuccessful, $shareWith, $expectedReturnData } } - public function dataTestCreateFederatedShare() { + public static function dataTestCreateFederatedShare(): array { return [ //shareWith, outgoingSharesAllowed, validShareWith, token, validToken, createSuccessful, expectedReturnData ['user@server', true, true, 'token', true, true, 'server', 31], diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php index c4c45c1aca5ae..81c67a29254a0 100644 --- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php +++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php @@ -1,5 +1,6 @@ share = $this->getMockBuilder(IShare::class)->getMock(); - $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') - ->disableOriginalConstructor()->getMock(); + $this->share = $this->createMock(IShare::class); + $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class); $this->federatedShareProvider->expects($this->any()) ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); $this->federatedShareProvider->expects($this->any()) @@ -98,11 +67,9 @@ protected function setUp(): void { $this->federatedShareProvider->expects($this->any())->method('getShareById') ->willReturn($this->share); - $this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') - ->disableOriginalConstructor()->getMock(); - $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler') - ->disableOriginalConstructor()->getMock(); - $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); + $this->notifications = $this->createMock(Notifications::class); + $this->addressHandler = $this->createMock(AddressHandler::class); + $this->userManager = $this->createMock(IUserManager::class); $this->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->request = $this->createMock(IRequest::class); $this->connection = $this->createMock(IDBConnection::class); @@ -149,7 +116,7 @@ public function testCreateShare(): void { 'file' )->willReturn($this->cloudFederationShare); - /** @var ICloudFederationProvider|\PHPUnit\Framework\MockObject\MockObject $provider */ + /** @var ICloudFederationProvider&MockObject $provider */ $this->cloudFederationProviderManager->expects($this->once()) ->method('getCloudFederationProvider') ->with('file') diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php index 002a8bac37406..fc6dbf7a6995d 100644 --- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php +++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php @@ -1,5 +1,6 @@ connection = Server::get(IDBConnection::class); - $this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') - ->disableOriginalConstructor() - ->getMock(); - $this->tokenHandler = $this->getMockBuilder('OCA\FederatedFileSharing\TokenHandler') - ->disableOriginalConstructor() - ->getMock(); - $this->l = $this->getMockBuilder(IL10N::class)->getMock(); + $this->notifications = $this->createMock(Notifications::class); + $this->tokenHandler = $this->createMock(TokenHandler::class); + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->willReturnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); }); - $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); - $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); - $this->config = $this->getMockBuilder(IConfig::class)->getMock(); - $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); + $this->logger = $this->createMock(LoggerInterface::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->config = $this->createMock(IConfig::class); + $this->userManager = $this->createMock(IUserManager::class); //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); - $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock(); + $this->addressHandler = $this->createMock(AddressHandler::class); $this->contactsManager = $this->createMock(IContactsManager::class); $this->cloudIdManager = new CloudIdManager( $this->contactsManager, @@ -122,16 +101,16 @@ protected function setUp(): void { $this->logger, ); - $this->shareManager = Server::get(\OCP\Share\IManager::class); + $this->shareManager = Server::get(IManager::class); } protected function tearDown(): void { - $this->connection->getQueryBuilder()->delete('share')->execute(); + $this->connection->getQueryBuilder()->delete('share')->executeStatement(); parent::tearDown(); } - public function dataTestCreate() { + public static function dataTestCreate(): array { return [ [null, null], [new \DateTime('2020-03-01T01:02:03'), '2020-03-01 01:02:03'], @@ -141,11 +120,11 @@ public function dataTestCreate() { /** * @dataProvider dataTestCreate */ - public function testCreate($expirationDate, $expectedDataDate): void { + public function testCreate(?\DateTime $expirationDate, ?string $expectedDataDate): void { $share = $this->shareManager->newShare(); - /** @var File|MockObject $node */ - $node = $this->getMockBuilder(File::class)->getMock(); + /** @var File&MockObject $node */ + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -190,7 +169,7 @@ public function testCreate($expirationDate, $expectedDataDate): void { $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->execute(); + ->executeQuery(); $data = $stmt->fetch(); $stmt->closeCursor(); @@ -227,7 +206,7 @@ public function testCreate($expirationDate, $expectedDataDate): void { public function testCreateCouldNotFindServer(): void { $share = $this->shareManager->newShare(); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -277,7 +256,7 @@ public function testCreateCouldNotFindServer(): void { $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->execute(); + ->executeQuery(); $data = $stmt->fetch(); $stmt->closeCursor(); @@ -288,7 +267,7 @@ public function testCreateCouldNotFindServer(): void { public function testCreateException(): void { $share = $this->shareManager->newShare(); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -338,7 +317,7 @@ public function testCreateException(): void { $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->execute(); + ->executeQuery(); $data = $stmt->fetch(); $stmt->closeCursor(); @@ -349,7 +328,7 @@ public function testCreateException(): void { public function testCreateShareWithSelf(): void { $share = $this->shareManager->newShare(); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -381,7 +360,7 @@ public function testCreateShareWithSelf(): void { $stmt = $qb->select('*') ->from('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) - ->execute(); + ->executeQuery(); $data = $stmt->fetch(); $stmt->closeCursor(); @@ -392,7 +371,7 @@ public function testCreateShareWithSelf(): void { public function testCreateAlreadyShared(): void { $share = $this->shareManager->newShare(); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -443,8 +422,8 @@ public function testCreateAlreadyShared(): void { /** * @dataProvider dataTestUpdate */ - public function testUpdate($owner, $sharedBy, $expirationDate): void { - $this->provider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') + public function testUpdate(string $owner, string $sharedBy, ?\DateTime $expirationDate): void { + $this->provider = $this->getMockBuilder(FederatedShareProvider::class) ->setConstructorArgs( [ $this->connection, @@ -460,11 +439,13 @@ public function testUpdate($owner, $sharedBy, $expirationDate): void { $this->cloudFederationProviderManager, $this->logger, ] - )->setMethods(['sendPermissionUpdate'])->getMock(); + ) + ->onlyMethods(['sendPermissionUpdate']) + ->getMock(); $share = $this->shareManager->newShare(); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -520,7 +501,7 @@ public function testUpdate($owner, $sharedBy, $expirationDate): void { $this->assertEquals($expirationDate, $share->getExpirationDate()); } - public function dataTestUpdate() { + public static function dataTestUpdate(): array { return [ ['sharedBy', 'shareOwner', new \DateTime('2020-03-01T01:02:03')], ['shareOwner', 'shareOwner', null], @@ -528,7 +509,7 @@ public function dataTestUpdate() { } public function testGetSharedBy(): void { - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -574,7 +555,7 @@ public function testGetSharedBy(): void { } public function testGetSharedByWithNode(): void { - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -621,7 +602,7 @@ public function testGetSharedByWithNode(): void { } public function testGetSharedByWithReshares(): void { - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -663,7 +644,7 @@ public function testGetSharedByWithReshares(): void { } public function testGetSharedByWithLimit(): void { - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(42); $node->method('getName')->willReturn('myFile'); @@ -713,7 +694,7 @@ public function testGetSharedByWithLimit(): void { $this->assertEquals('user2@server.com', $shares[0]->getSharedWith()); } - public function dataDeleteUser() { + public static function dataDeleteUser(): array { return [ ['a', 'b', 'c', 'a', true], ['a', 'b', 'c', 'b', false], @@ -732,7 +713,7 @@ public function dataDeleteUser() { * @param string $deletedUser The user that is deleted * @param bool $rowDeleted Is the row deleted in this setup */ - public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $rowDeleted): void { + public function testDeleteUser(string $owner, string $initiator, string $recipient, string $deletedUser, bool $rowDeleted): void { $qb = $this->connection->getQueryBuilder(); $qb->insert('share') ->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_REMOTE)) @@ -742,7 +723,7 @@ public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $ro ->setValue('item_type', $qb->createNamedParameter('file')) ->setValue('item_source', $qb->createNamedParameter(42)) ->setValue('file_source', $qb->createNamedParameter(42)) - ->execute(); + ->executeStatement(); $id = $qb->getLastInsertId(); @@ -754,7 +735,7 @@ public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $ro ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id)) ); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $data = $cursor->fetchAll(); $cursor->closeCursor(); @@ -763,11 +744,8 @@ public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $ro /** * @dataProvider dataTestIsOutgoingServer2serverShareEnabled - * - * @param string $isEnabled - * @param bool $expected */ - public function testIsOutgoingServer2serverShareEnabled($internalOnly, $isEnabled, $expected): void { + public function testIsOutgoingServer2serverShareEnabled(bool $internalOnly, string $isEnabled, bool $expected): void { $this->gsConfig->expects($this->once())->method('onlyInternalFederation') ->willReturn($internalOnly); $this->config->expects($this->any())->method('getAppValue') @@ -779,7 +757,7 @@ public function testIsOutgoingServer2serverShareEnabled($internalOnly, $isEnable ); } - public function dataTestIsOutgoingServer2serverShareEnabled() { + public static function dataTestIsOutgoingServer2serverShareEnabled(): array { return [ [false, 'yes', true], [false, 'no', false], @@ -790,11 +768,8 @@ public function dataTestIsOutgoingServer2serverShareEnabled() { /** * @dataProvider dataTestIsIncomingServer2serverShareEnabled - * - * @param string $isEnabled - * @param bool $expected */ - public function testIsIncomingServer2serverShareEnabled($onlyInternal, $isEnabled, $expected): void { + public function testIsIncomingServer2serverShareEnabled(bool $onlyInternal, string $isEnabled, bool $expected): void { $this->gsConfig->expects($this->once())->method('onlyInternalFederation') ->willReturn($onlyInternal); $this->config->expects($this->any())->method('getAppValue') @@ -806,7 +781,7 @@ public function testIsIncomingServer2serverShareEnabled($onlyInternal, $isEnable ); } - public function dataTestIsIncomingServer2serverShareEnabled() { + public static function dataTestIsIncomingServer2serverShareEnabled(): array { return [ [false, 'yes', true], [false, 'no', false], @@ -817,11 +792,8 @@ public function dataTestIsIncomingServer2serverShareEnabled() { /** * @dataProvider dataTestIsLookupServerQueriesEnabled - * - * @param string $isEnabled - * @param bool $expected */ - public function testIsLookupServerQueriesEnabled($gsEnabled, $isEnabled, $expected): void { + public function testIsLookupServerQueriesEnabled(bool $gsEnabled, string $isEnabled, bool $expected): void { $this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled') ->willReturn($gsEnabled); $this->config->expects($this->any())->method('getAppValue') @@ -834,7 +806,7 @@ public function testIsLookupServerQueriesEnabled($gsEnabled, $isEnabled, $expect } - public function dataTestIsLookupServerQueriesEnabled() { + public static function dataTestIsLookupServerQueriesEnabled(): array { return [ [true, 'yes', true], [true, 'no', true], @@ -848,11 +820,8 @@ public function dataTestIsLookupServerQueriesEnabled() { /** * @dataProvider dataTestIsLookupServerUploadEnabled - * - * @param string $isEnabled - * @param bool $expected */ - public function testIsLookupServerUploadEnabled($gsEnabled, $isEnabled, $expected): void { + public function testIsLookupServerUploadEnabled(bool $gsEnabled, string $isEnabled, bool $expected): void { $this->gsConfig->expects($this->once())->method('isGlobalScaleEnabled') ->willReturn($gsEnabled); $this->config->expects($this->any())->method('getAppValue') @@ -864,7 +833,7 @@ public function testIsLookupServerUploadEnabled($gsEnabled, $isEnabled, $expecte ); } - public function dataTestIsLookupServerUploadEnabled() { + public static function dataTestIsLookupServerUploadEnabled(): array { return [ [true, 'yes', false], [true, 'no', false], @@ -880,8 +849,8 @@ public function testGetSharesInFolder(): void { $userManager = Server::get(IUserManager::class); $rootFolder = Server::get(IRootFolder::class); - $u1 = $userManager->createUser('testFed', md5(time())); - $u2 = $userManager->createUser('testFed2', md5(time())); + $u1 = $userManager->createUser('testFed', md5((string)time())); + $u2 = $userManager->createUser('testFed2', md5((string)time())); $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); $file1 = $folder1->newFile('bar1'); @@ -934,7 +903,7 @@ public function testGetAccessList(): void { $userManager = Server::get(IUserManager::class); $rootFolder = Server::get(IRootFolder::class); - $u1 = $userManager->createUser('testFed', md5(time())); + $u1 = $userManager->createUser('testFed', md5((string)time())); $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); $file1 = $folder1->newFile('bar1'); diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php index 7ac4e964362c0..94d08b5aa5dda 100644 --- a/apps/federatedfilesharing/tests/NotificationsTest.php +++ b/apps/federatedfilesharing/tests/NotificationsTest.php @@ -1,5 +1,6 @@ jobList = $this->getMockBuilder('OCP\BackgroundJob\IJobList')->getMock(); - $this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock(); - $this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock(); - $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler') - ->disableOriginalConstructor()->getMock(); + $this->jobList = $this->createMock(IJobList::class); + $this->discoveryService = $this->createMock(IDiscoveryService::class); + $this->httpClientService = $this->createMock(IClientService::class); + $this->addressHandler = $this->createMock(AddressHandler::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); $this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); @@ -58,14 +44,11 @@ protected function setUp(): void { } /** - * get instance of Notifications class - * - * @param array $mockedMethods methods which should be mocked - * @return Notifications | \PHPUnit\Framework\MockObject\MockObject + * @return Notifications|MockObject */ private function getInstance(array $mockedMethods = []) { if (empty($mockedMethods)) { - $instance = new Notifications( + return new Notifications( $this->addressHandler, $this->httpClientService, $this->discoveryService, @@ -75,34 +58,30 @@ private function getInstance(array $mockedMethods = []) { $this->eventDispatcher, $this->logger, ); - } else { - $instance = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') - ->setConstructorArgs( - [ - $this->addressHandler, - $this->httpClientService, - $this->discoveryService, - $this->jobList, - $this->cloudFederationProviderManager, - $this->cloudFederationFactory, - $this->eventDispatcher, - $this->logger, - ] - )->setMethods($mockedMethods)->getMock(); } - return $instance; + return $this->getMockBuilder(Notifications::class) + ->setConstructorArgs( + [ + $this->addressHandler, + $this->httpClientService, + $this->discoveryService, + $this->jobList, + $this->cloudFederationProviderManager, + $this->cloudFederationFactory, + $this->eventDispatcher, + $this->logger, + ] + ) + ->onlyMethods($mockedMethods) + ->getMock(); } /** * @dataProvider dataTestSendUpdateToRemote - * - * @param int $try - * @param array $httpRequestResult - * @param bool $expected */ - public function testSendUpdateToRemote($try, $httpRequestResult, $expected): void { + public function testSendUpdateToRemote(int $try, array $httpRequestResult, bool $expected): void { $remote = 'http://remote'; $id = 42; $timestamp = 63576; @@ -120,7 +99,7 @@ public function testSendUpdateToRemote($try, $httpRequestResult, $expected): voi if ($try === 0 && $expected === false) { $this->jobList->expects($this->once())->method('add') ->with( - 'OCA\FederatedFileSharing\BackgroundJob\RetryJob', + RetryJob::class, [ 'remote' => $remote, 'remoteId' => $id, @@ -141,7 +120,7 @@ public function testSendUpdateToRemote($try, $httpRequestResult, $expected): voi } - public function dataTestSendUpdateToRemote() { + public static function dataTestSendUpdateToRemote(): array { return [ // test if background job is added correctly [0, ['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 200]]])], true], diff --git a/apps/federatedfilesharing/tests/Settings/AdminTest.php b/apps/federatedfilesharing/tests/Settings/AdminTest.php index efbe763c63303..1eb75003b4f4b 100644 --- a/apps/federatedfilesharing/tests/Settings/AdminTest.php +++ b/apps/federatedfilesharing/tests/Settings/AdminTest.php @@ -1,4 +1,6 @@ federatedShareProvider ->expects($this->once()) ->method('isOutgoingServer2serverShareEnabled') @@ -98,20 +96,24 @@ public function testGetForm($state): void { $this->gsConfig->expects($this->once())->method('onlyInternalFederation') ->willReturn($state); + $calls = [ + ['internalOnly', $state], + ['sharingFederatedDocUrl', 'doc-link'], + ['outgoingServer2serverShareEnabled', $state], + ['incomingServer2serverShareEnabled', $state], + ['federatedGroupSharingSupported', $state], + ['outgoingServer2serverGroupShareEnabled', $state], + ['incomingServer2serverGroupShareEnabled', $state], + ['lookupServerEnabled', $state], + ['lookupServerUploadEnabled', $state], + ['federatedTrustedShareAutoAccept', $state], + ]; $this->initialState->expects($this->exactly(10)) ->method('provideInitialState') - ->withConsecutive( - ['internalOnly', $state], - ['sharingFederatedDocUrl', 'doc-link'], - ['outgoingServer2serverShareEnabled', $state], - ['incomingServer2serverShareEnabled', $state], - ['federatedGroupSharingSupported', $state], - ['outgoingServer2serverGroupShareEnabled', $state], - ['incomingServer2serverGroupShareEnabled', $state], - ['lookupServerEnabled', $state], - ['lookupServerUploadEnabled', $state], - ['federatedTrustedShareAutoAccept', $state] - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertSame($expected, func_get_args()); + }); $expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], ''); $this->assertEquals($expected, $this->admin->getForm()); diff --git a/apps/federatedfilesharing/tests/TestCase.php b/apps/federatedfilesharing/tests/TestCase.php index b9787f2ffab6d..1536e1b3375e5 100644 --- a/apps/federatedfilesharing/tests/TestCase.php +++ b/apps/federatedfilesharing/tests/TestCase.php @@ -1,5 +1,6 @@ setUser(null); Filesystem::tearDown(); Server::get(IUserSession::class)->login($user, $password); - \OC::$server->getUserFolder($user); + \OCP\Server::get(IRootFolder::class)->getUserFolder($user); \OC_Util::setupFS($user); } diff --git a/apps/federatedfilesharing/tests/TokenHandlerTest.php b/apps/federatedfilesharing/tests/TokenHandlerTest.php index 9ed2077985747..7a2102740136d 100644 --- a/apps/federatedfilesharing/tests/TokenHandlerTest.php +++ b/apps/federatedfilesharing/tests/TokenHandlerTest.php @@ -1,5 +1,6 @@ assertInstanceOf(IFilter::class, $filter); } /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetIdentifier($filterClass): void { + public function testGetIdentifier(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getIdentifier()); @@ -46,9 +46,8 @@ public function testGetIdentifier($filterClass): void { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetName($filterClass): void { + public function testGetName(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getName()); @@ -56,9 +55,8 @@ public function testGetName($filterClass): void { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetPriority($filterClass): void { + public function testGetPriority(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $priority = $filter->getPriority(); @@ -69,9 +67,8 @@ public function testGetPriority($filterClass): void { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetIcon($filterClass): void { + public function testGetIcon(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getIcon()); @@ -80,9 +77,8 @@ public function testGetIcon($filterClass): void { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testFilterTypes($filterClass): void { + public function testFilterTypes(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsArray($filter->filterTypes([])); @@ -90,9 +86,8 @@ public function testFilterTypes($filterClass): void { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testAllowedApps($filterClass): void { + public function testAllowedApps(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsArray($filter->allowedApps()); diff --git a/apps/files/tests/Activity/ProviderTest.php b/apps/files/tests/Activity/ProviderTest.php index 7b91e9808423d..ed52c76ba2899 100644 --- a/apps/files/tests/Activity/ProviderTest.php +++ b/apps/files/tests/Activity/ProviderTest.php @@ -1,4 +1,6 @@ contactsManager, $this->eventMerger, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); } return new Provider( @@ -89,7 +82,7 @@ protected function getProvider(array $methods = []) { ); } - public function dataGetFile() { + public static function dataGetFile(): array { return [ [[42 => '/FortyTwo.txt'], null, '42', 'FortyTwo.txt', 'FortyTwo.txt'], [['23' => '/Twenty/Three.txt'], null, '23', 'Three.txt', 'Twenty/Three.txt'], @@ -99,13 +92,8 @@ public function dataGetFile() { /** * @dataProvider dataGetFile - * @param mixed $parameter - * @param mixed $eventId - * @param int $id - * @param string $name - * @param string $path */ - public function testGetFile($parameter, $eventId, $id, $name, $path): void { + public function testGetFile(array|string $parameter, ?int $eventId, string $id, string $name, string $path): void { $provider = $this->getProvider(); if ($eventId !== null) { @@ -139,7 +127,7 @@ public function testGetFileThrows(): void { self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]); } - public function dataGetUser() { + public static function dataGetUser(): array { return [ ['test', 'Test user', null, ['type' => 'user', 'id' => 'test', 'name' => 'Test user']], ['test@http://localhost', null, ['user' => 'test', 'displayId' => 'test@localhost', 'remote' => 'localhost', 'name' => null], ['type' => 'user', 'id' => 'test', 'name' => 'test@localhost', 'server' => 'localhost']], @@ -150,10 +138,6 @@ public function dataGetUser() { /** * @dataProvider dataGetUser - * @param string $uid - * @param string|null $userDisplayName - * @param array|null $cloudIdData - * @param array $expected */ public function testGetUser(string $uid, ?string $userDisplayName, ?array $cloudIdData, array $expected): void { $provider = $this->getProvider(); diff --git a/apps/files/tests/Activity/Setting/GenericTest.php b/apps/files/tests/Activity/Setting/GenericTest.php index 1dc551be92793..7e549ce9dc04b 100644 --- a/apps/files/tests/Activity/Setting/GenericTest.php +++ b/apps/files/tests/Activity/Setting/GenericTest.php @@ -1,4 +1,6 @@ assertInstanceOf(ISetting::class, $setting); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetIdentifier($settingClass): void { + public function testGetIdentifier(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsString($setting->getIdentifier()); @@ -41,9 +41,8 @@ public function testGetIdentifier($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetName($settingClass): void { + public function testGetName(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsString($setting->getName()); @@ -51,9 +50,8 @@ public function testGetName($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetPriority($settingClass): void { + public function testGetPriority(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $priority = $setting->getPriority(); @@ -64,9 +62,8 @@ public function testGetPriority($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeStream($settingClass): void { + public function testCanChangeStream(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->canChangeStream()); @@ -74,9 +71,8 @@ public function testCanChangeStream($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledStream($settingClass): void { + public function testIsDefaultEnabledStream(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledStream()); @@ -84,9 +80,8 @@ public function testIsDefaultEnabledStream($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeMail($settingClass): void { + public function testCanChangeMail(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->canChangeMail()); @@ -94,9 +89,8 @@ public function testCanChangeMail($settingClass): void { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledMail($settingClass): void { + public function testIsDefaultEnabledMail(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledMail()); diff --git a/apps/files/tests/AdvancedCapabilitiesTest.php b/apps/files/tests/AdvancedCapabilitiesTest.php index af38c51a4a2b3..8f4a845b708c6 100644 --- a/apps/files/tests/AdvancedCapabilitiesTest.php +++ b/apps/files/tests/AdvancedCapabilitiesTest.php @@ -18,6 +18,7 @@ class AdvancedCapabilitiesTest extends TestCase { protected AdvancedCapabilities $capabilities; protected function setUp(): void { + parent::setUp(); $this->service = $this->createMock(SettingsService::class); $this->capabilities = new AdvancedCapabilities($this->service); } diff --git a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php index e31b157481536..3f811fca40791 100644 --- a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php +++ b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php @@ -1,5 +1,6 @@ logger = Server::get(LoggerInterface::class); } - protected function cleanMapping($table) { + protected function cleanMapping(string $table): void { $query = $this->connection->getQueryBuilder(); - $query->delete($table)->execute(); + $query->delete($table)->executeStatement(); } - protected function getMappings($table) { + protected function getMappings(string $table): array { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from($table); - $result = $query->execute(); + $result = $query->executeQuery(); $mapping = $result->fetchAll(); $result->closeCursor(); @@ -61,7 +62,7 @@ public function testClearSystemTagMappings(): void { 'storage' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), 'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), 'path_hash' => $query->createNamedParameter(md5('apps/files/tests/deleteorphanedtagsjobtest.php')), - ])->execute(); + ])->executeStatement(); $fileId = $query->getLastInsertId(); // Existing file @@ -71,7 +72,7 @@ public function testClearSystemTagMappings(): void { 'objectid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), 'objecttype' => $query->createNamedParameter('files'), 'systemtagid' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); // Non-existing file $query = $this->connection->getQueryBuilder(); @@ -80,13 +81,13 @@ public function testClearSystemTagMappings(): void { 'objectid' => $query->createNamedParameter($fileId + 1, IQueryBuilder::PARAM_INT), 'objecttype' => $query->createNamedParameter('files'), 'systemtagid' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); $mapping = $this->getMappings('systemtag_object_mapping'); $this->assertCount(2, $mapping); $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger); - $this->invokePrivate($job, 'cleanSystemTags'); + self::invokePrivate($job, 'cleanSystemTags'); $mapping = $this->getMappings('systemtag_object_mapping'); $this->assertCount(1, $mapping); @@ -94,7 +95,7 @@ public function testClearSystemTagMappings(): void { $query = $this->connection->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->execute(); + ->executeStatement(); $this->cleanMapping('systemtag_object_mapping'); } @@ -110,7 +111,7 @@ public function testClearUserTagMappings(): void { 'storage' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), 'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), 'path_hash' => $query->createNamedParameter(md5('apps/files/tests/deleteorphanedtagsjobtest.php')), - ])->execute(); + ])->executeStatement(); $fileId = $query->getLastInsertId(); // Existing file @@ -120,7 +121,7 @@ public function testClearUserTagMappings(): void { 'objid' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), 'type' => $query->createNamedParameter('files'), 'categoryid' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); // Non-existing file $query = $this->connection->getQueryBuilder(); @@ -129,13 +130,13 @@ public function testClearUserTagMappings(): void { 'objid' => $query->createNamedParameter($fileId + 1, IQueryBuilder::PARAM_INT), 'type' => $query->createNamedParameter('files'), 'categoryid' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); $mapping = $this->getMappings('vcategory_to_object'); $this->assertCount(2, $mapping); $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger); - $this->invokePrivate($job, 'cleanUserTags'); + self::invokePrivate($job, 'cleanUserTags'); $mapping = $this->getMappings('vcategory_to_object'); $this->assertCount(1, $mapping); @@ -143,7 +144,7 @@ public function testClearUserTagMappings(): void { $query = $this->connection->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->execute(); + ->executeStatement(); $this->cleanMapping('vcategory_to_object'); } @@ -159,7 +160,7 @@ public function testClearComments(): void { 'storage' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), 'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), 'path_hash' => $query->createNamedParameter(md5('apps/files/tests/deleteorphanedtagsjobtest.php')), - ])->execute(); + ])->executeStatement(); $fileId = $query->getLastInsertId(); // Existing file @@ -170,7 +171,7 @@ public function testClearComments(): void { 'object_type' => $query->createNamedParameter('files'), 'actor_id' => $query->createNamedParameter('Alice', IQueryBuilder::PARAM_INT), 'actor_type' => $query->createNamedParameter('users'), - ])->execute(); + ])->executeStatement(); // Non-existing file $query = $this->connection->getQueryBuilder(); @@ -180,13 +181,13 @@ public function testClearComments(): void { 'object_type' => $query->createNamedParameter('files'), 'actor_id' => $query->createNamedParameter('Alice', IQueryBuilder::PARAM_INT), 'actor_type' => $query->createNamedParameter('users'), - ])->execute(); + ])->executeStatement(); $mapping = $this->getMappings('comments'); $this->assertCount(2, $mapping); $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger); - $this->invokePrivate($job, 'cleanComments'); + self::invokePrivate($job, 'cleanComments'); $mapping = $this->getMappings('comments'); $this->assertCount(1, $mapping); @@ -194,7 +195,7 @@ public function testClearComments(): void { $query = $this->connection->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->execute(); + ->executeStatement(); $this->cleanMapping('comments'); } @@ -210,7 +211,7 @@ public function testClearCommentReadMarks(): void { 'storage' => $query->createNamedParameter(1337, IQueryBuilder::PARAM_INT), 'path' => $query->createNamedParameter('apps/files/tests/deleteorphanedtagsjobtest.php'), 'path_hash' => $query->createNamedParameter(md5('apps/files/tests/deleteorphanedtagsjobtest.php')), - ])->execute(); + ])->executeStatement(); $fileId = $query->getLastInsertId(); // Existing file @@ -220,7 +221,7 @@ public function testClearCommentReadMarks(): void { 'object_id' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT), 'object_type' => $query->createNamedParameter('files'), 'user_id' => $query->createNamedParameter('Alice', IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); // Non-existing file $query = $this->connection->getQueryBuilder(); @@ -229,13 +230,13 @@ public function testClearCommentReadMarks(): void { 'object_id' => $query->createNamedParameter($fileId + 1, IQueryBuilder::PARAM_INT), 'object_type' => $query->createNamedParameter('files'), 'user_id' => $query->createNamedParameter('Alice', IQueryBuilder::PARAM_INT), - ])->execute(); + ])->executeStatement(); $mapping = $this->getMappings('comments_read_markers'); $this->assertCount(2, $mapping); $job = new DeleteOrphanedItems($this->timeFactory, $this->connection, $this->logger); - $this->invokePrivate($job, 'cleanCommentMarkers'); + self::invokePrivate($job, 'cleanCommentMarkers'); $mapping = $this->getMappings('comments_read_markers'); $this->assertCount(1, $mapping); @@ -243,7 +244,7 @@ public function testClearCommentReadMarks(): void { $query = $this->connection->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) - ->execute(); + ->executeStatement(); $this->cleanMapping('comments_read_markers'); } } diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php index ce602805aa25c..00d9ed823f9f3 100644 --- a/apps/files/tests/BackgroundJob/ScanFilesTest.php +++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php @@ -1,5 +1,6 @@ mountCache = Server::get(IUserMountCache::class); - $this->scanFiles = $this->getMockBuilder('\OCA\Files\BackgroundJob\ScanFiles') + $this->scanFiles = $this->getMockBuilder(ScanFiles::class) ->setConstructorArgs([ $config, $dispatcher, @@ -54,12 +53,12 @@ protected function setUp(): void { $connection, $this->createMock(ITimeFactory::class) ]) - ->setMethods(['runScanner']) + ->onlyMethods(['runScanner']) ->getMock(); } - private function runJob() { - $this->invokePrivate($this->scanFiles, 'run', [[]]); + private function runJob(): void { + self::invokePrivate($this->scanFiles, 'run', [[]]); } private function getUser(string $userId): IUser { diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php index 389ede2a74ded..54b5ac6c12f64 100644 --- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php +++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php @@ -1,5 +1,6 @@ connection->getQueryBuilder(); $query->select('*') ->from('filecache') @@ -64,7 +65,7 @@ protected function getFile($fileId) { return $query->executeQuery()->fetchAll(); } - protected function getMounts($storageId) { + protected function getMounts(int $storageId): array { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from('mounts') @@ -76,12 +77,8 @@ protected function getMounts($storageId) { * Test clearing orphaned files */ public function testClearFiles(): void { - $input = $this->getMockBuilder(InputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $input = $this->createMock(InputInterface::class); + $output = $this->createMock(OutputInterface::class); $rootFolder = Server::get(IRootFolder::class); @@ -112,14 +109,18 @@ public function testClearFiles(): void { $this->assertSame(1, $deletedRows, 'Asserts that storage got deleted'); // parent folder, `files`, ´test` and `welcome.txt` => 4 elements + $calls = [ + '3 orphaned file cache entries deleted', + '0 orphaned file cache extended entries deleted', + '1 orphaned mount entries deleted', + ]; $output ->expects($this->exactly(3)) ->method('writeln') - ->withConsecutive( - ['3 orphaned file cache entries deleted'], - ['0 orphaned file cache extended entries deleted'], - ['1 orphaned mount entries deleted'], - ); + ->willReturnCallback(function (string $message) use (&$calls) { + $expected = array_shift($calls); + $this->assertSame($expected, $message); + }); $this->command->execute($input, $output); diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php index 429d3c06f661b..0c9d7a4fa6e11 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -1,5 +1,6 @@ request = $this->getMockBuilder(IRequest::class) - ->disableOriginalConstructor() - ->getMock(); + $this->request = $this->createMock(IRequest::class); $this->user = $this->createMock(IUser::class); $this->user->expects($this->any()) ->method('getUID') @@ -83,19 +69,11 @@ protected function setUp(): void { $userSession->expects($this->any()) ->method('getUser') ->willReturn($this->user); - $this->tagService = $this->getMockBuilder(TagService::class) - ->disableOriginalConstructor() - ->getMock(); - $this->shareManager = $this->getMockBuilder(IManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->preview = $this->getMockBuilder(IPreview::class) - ->disableOriginalConstructor() - ->getMock(); + $this->tagService = $this->createMock(TagService::class); + $this->shareManager = $this->createMock(IManager::class); + $this->preview = $this->createMock(IPreview::class); $this->config = $this->createMock(IConfig::class); - $this->userFolder = $this->getMockBuilder(Folder::class) - ->disableOriginalConstructor() - ->getMock(); + $this->userFolder = $this->createMock(Folder::class); $this->userConfig = $this->createMock(UserConfig::class); $this->viewConfig = $this->createMock(ViewConfig::class); $this->l10n = $this->createMock(IL10N::class); diff --git a/apps/files/tests/Controller/ConversionApiControllerTest.php b/apps/files/tests/Controller/ConversionApiControllerTest.php index a2f1fccd978a6..659fbe1a9560d 100644 --- a/apps/files/tests/Controller/ConversionApiControllerTest.php +++ b/apps/files/tests/Controller/ConversionApiControllerTest.php @@ -1,5 +1,6 @@ expectException(OCSNotFoundException::class); $this->conversionApiController->convert(42, 'image/png'); } - public function testThrowsOcsException() { + public function testThrowsOcsException(): void { $this->userFolder->method('getFirstNodeById')->with(42)->willReturn($this->file); $this->fileConversionManager->method('convert')->willThrowException(new \Exception()); @@ -73,7 +74,7 @@ public function testThrowsOcsException() { $this->conversionApiController->convert(42, 'image/png'); } - public function testConvert() { + public function testConvert(): void { $convertedFileAbsolutePath = $this->user . '/files/test.png'; $this->userFolder->method('getFirstNodeById')->with(42)->willReturn($this->file); diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index dd76e81405432..93ef98bdec74e 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -1,5 +1,6 @@ assertEquals($expected, $this->viewController->index('MyDir', 'MyView')); } - public function dataTestShortRedirect(): array { + public static function dataTestShortRedirect(): array { // openfile is true by default // opendetails is undefined by default // both will be evaluated as truthy @@ -212,7 +213,7 @@ public function dataTestShortRedirect(): array { /** * @dataProvider dataTestShortRedirect */ - public function testShortRedirect($openfile, $opendetails, $result) { + public function testShortRedirect(?string $openfile, ?string $opendetails, string $result): void { $this->appManager->expects($this->any()) ->method('isEnabledForUser') ->with('files') @@ -239,7 +240,7 @@ public function testShortRedirect($openfile, $opendetails, $result) { ->with(123456) ->willReturn($node); - $response = $this->viewController->showFile(123456, $opendetails, $openfile); + $response = $this->viewController->showFile('123456', $opendetails, $openfile); $this->assertStringContainsString($result, $response->getHeaders()['Location']); } @@ -248,13 +249,13 @@ public function testShowFileRouteWithTrashedFile(): void { ->method('isEnabledForUser') ->willReturn(true); - $parentNode = $this->getMockBuilder(Folder::class)->getMock(); + $parentNode = $this->createMock(Folder::class); $parentNode->expects($this->once()) ->method('getPath') ->willReturn('testuser1/files_trashbin/files/test.d1462861890/sub'); - $baseFolderFiles = $this->getMockBuilder(Folder::class)->getMock(); - $baseFolderTrash = $this->getMockBuilder(Folder::class)->getMock(); + $baseFolderFiles = $this->createMock(Folder::class); + $baseFolderTrash = $this->createMock(Folder::class); $this->rootFolder->expects($this->any()) ->method('getUserFolder') @@ -270,7 +271,7 @@ public function testShowFileRouteWithTrashedFile(): void { ->with(123) ->willReturn(null); - $node = $this->getMockBuilder(File::class)->getMock(); + $node = $this->createMock(File::class); $node->expects($this->once()) ->method('getParent') ->willReturn($parentNode); diff --git a/apps/files/tests/HelperTest.php b/apps/files/tests/HelperTest.php index 5900e94215c7c..cb1fc5ed66dda 100644 --- a/apps/files/tests/HelperTest.php +++ b/apps/files/tests/HelperTest.php @@ -1,15 +1,17 @@ withAnyParameters() ->willReturn($user); - $this->root = \OC::$server->getUserFolder(); + $this->root = \OCP\Server::get(IRootFolder::class)->getUserFolder($this->user); $this->tagger = Server::get(ITagManager::class)->load('files'); - $this->tagService = $this->getTagService(['addActivity']); + $this->tagService = $this->getTagService(); } - /** - * @param array $methods - * @return TagService|\PHPUnit\Framework\MockObject\MockObject - */ - protected function getTagService(array $methods = []) { + protected function getTagService(array $methods = []): TagService&MockObject { return $this->getMockBuilder(TagService::class) ->setConstructorArgs([ $this->userSession, @@ -88,7 +67,7 @@ protected function getTagService(array $methods = []) { $this->tagger, $this->root, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); } @@ -98,6 +77,8 @@ protected function tearDown(): void { if ($user !== null) { $user->delete(); } + + parent::tearDown(); } public function testUpdateFileTags(): void { diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index c3b829825c2e9..95ad129c4660a 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -157,7 +157,7 @@ class RegistrationContext { /** @var ServiceRegistration<\OCP\Files\Conversion\IConversionProvider>[] */ private array $fileConversionProviders = []; - + /** @var ServiceRegistration[] */ private $mailProviders = []; diff --git a/tests/lib/TextProcessing/TextProcessingTest.php b/tests/lib/TextProcessing/TextProcessingTest.php index 84c5492a4a245..1bbb9cf527e8d 100644 --- a/tests/lib/TextProcessing/TextProcessingTest.php +++ b/tests/lib/TextProcessing/TextProcessingTest.php @@ -118,7 +118,7 @@ protected function setUp(): void { $this->eventDispatcher = new EventDispatcher( new \Symfony\Component\EventDispatcher\EventDispatcher(), $this->serverContainer, - \OC::$server->get(LoggerInterface::class), + \OCP\Server::get(LoggerInterface::class), ); $this->registrationContext = $this->createMock(RegistrationContext::class); @@ -176,11 +176,11 @@ protected function setUp(): void { $this->manager = new Manager( $this->serverContainer, $this->coordinator, - \OC::$server->get(LoggerInterface::class), + \OCP\Server::get(LoggerInterface::class), $this->jobList, $this->taskMapper, $config, - \OC::$server->get(\OCP\TaskProcessing\IManager::class), + $this->createMock(\OCP\TaskProcessing\IManager::class), ); } @@ -239,7 +239,7 @@ public function testProviderShouldBeRegisteredAndScheduled(): void { // run background job $bgJob = new TaskBackgroundJob( - \OC::$server->get(ITimeFactory::class), + \OCP\Server::get(ITimeFactory::class), $this->manager, $this->eventDispatcher, ); @@ -314,7 +314,7 @@ public function testTaskFailure(): void { // run background job $bgJob = new TaskBackgroundJob( - \OC::$server->get(ITimeFactory::class), + \OCP\Server::get(ITimeFactory::class), $this->manager, $this->eventDispatcher, ); @@ -343,9 +343,9 @@ public function testOldTasksShouldBeCleanedUp(): void { $this->currentTime = $this->currentTime->add(new \DateInterval('P1Y')); // run background job $bgJob = new RemoveOldTasksBackgroundJob( - \OC::$server->get(ITimeFactory::class), + \OCP\Server::get(ITimeFactory::class), $this->taskMapper, - \OC::$server->get(LoggerInterface::class), + \OCP\Server::get(LoggerInterface::class), ); $bgJob->setArgument([]); $bgJob->start($this->jobList);