diff --git a/REUSE.toml b/REUSE.toml index 05a49bd80e4..b799a0f76ad 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -250,7 +250,7 @@ SPDX-FileCopyrightText = "2023 Nextcloud GmbH and Nextcloud contributors" SPDX-License-Identifier = "AGPL-3.0-or-later" [[annotations]] -path = ["apps/dav/lib/ExampleContentFiles/exampleContact.vcf", "tests/data/testvideo-remote-file.mp4"] +path = ["apps/dav/lib/ExampleContentFiles/exampleContact.vcf", "tests/data/testvideo-remote-file.mp4", "tests/lib/AppFramework/Middleware/Mock/UseSessionController.php", "tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php", "tests/lib/AppFramework/Middleware/Security/Mock/RateLimitingMiddlewareController.php"] precedence = "aggregate" SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors" SPDX-License-Identifier = "AGPL-3.0-or-later" diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php index 13907757954..2931ff4113b 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -34,10 +34,6 @@ class Result extends BaseResult { * @deprecated 20.0.0 */ public $fileName; - /** - * @deprecated 20.0.0 - */ - public int $fileId; /** * @throws NotFoundException @@ -51,7 +47,10 @@ class Result extends BaseResult { */ public string $authorName, string $path, - int $fileId, + /** + * @deprecated 20.0.0 + */ + public int $fileId, ) { parent::__construct( $comment->getId(), @@ -63,7 +62,6 @@ class Result extends BaseResult { $this->authorId = $comment->getActorId(); $this->fileName = basename($path); $this->path = $this->getVisiblePath($path); - $this->fileId = $fileId; } /** diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index ff66274909d..6cfb712984f 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -24,6 +24,7 @@ use OCA\DAV\Connector\Sabre\Principal; use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; @@ -78,7 +79,7 @@ $calDavBackend = new CalDavBackend( $config, Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class), Server::get(FederatedCalendarMapper::class), - Server::get(\OCP\ICacheFactory::class), + Server::get(ICacheFactory::class), true ); diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php index de5f5b987d2..05d9ea9d6ec 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php @@ -11,6 +11,7 @@ namespace OCA\DAV\CalDAV\Federation; use OCA\DAV\BackgroundJob\FederatedCalendarSyncJob; use OCA\DAV\CalDAV\Federation\Protocol\CalendarFederationProtocolV1; +use OCA\DAV\CalDAV\Federation\Protocol\CalendarProtocolParseException; use OCA\DAV\CalDAV\Federation\Protocol\ICalendarFederationProtocol; use OCA\DAV\DAV\Sharing\Backend as DavSharingBackend; use OCP\AppFramework\Http; @@ -74,7 +75,7 @@ class CalendarFederationProvider implements ICloudFederationProvider { case CalendarFederationProtocolV1::VERSION: try { $protocol = CalendarFederationProtocolV1::parse($rawProtocol); - } catch (Protocol\CalendarProtocolParseException $e) { + } catch (CalendarProtocolParseException $e) { throw new ProviderCouldNotAddShareException( 'Invalid protocol data (v1)', '', diff --git a/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php b/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php index ec9874427ba..20fbd0194ce 100644 --- a/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php +++ b/apps/dav/lib/DAV/RemoteUserPrincipalBackend.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace OCA\DAV\DAV; use OCA\DAV\DAV\Sharing\SharingMapper; +use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; use Sabre\DAVACL\PrincipalBackend\BackendInterface; @@ -102,7 +103,7 @@ class RemoteUserPrincipalBackend implements BackendInterface { } /** - * @return array{'{DAV:}displayname': string, '{http://nextcloud.com/ns}cloud-id': \OCP\Federation\ICloudId, uri: string} + * @return array{'{DAV:}displayname': string, '{http://nextcloud.com/ns}cloud-id': ICloudId, uri: string} */ private function principalUriToPrincipal(string $principalUri): array { [, $name] = \Sabre\Uri\split($principalUri); diff --git a/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php index 9d22befa201..60b162116cd 100644 --- a/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/PropFindMonitorPluginTest.php @@ -105,9 +105,7 @@ class PropFindMonitorPluginTest extends TestCase { ]; } - /** - * @dataProvider dataTest - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')] public function test(array $queries, $expectedLogCalls): void { $this->plugin->initialize($this->server); $this->server->expects($this->once())->method('getPluginQueries') diff --git a/apps/encryption/lib/Controller/RecoveryController.php b/apps/encryption/lib/Controller/RecoveryController.php index d75406e6319..e7fb6bafb67 100644 --- a/apps/encryption/lib/Controller/RecoveryController.php +++ b/apps/encryption/lib/Controller/RecoveryController.php @@ -25,13 +25,13 @@ class RecoveryController extends Controller { * @param Recovery $recovery */ public function __construct( - $AppName, + $appName, IRequest $request, private IConfig $config, private IL10N $l, private Recovery $recovery, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/encryption/lib/Controller/SettingsController.php b/apps/encryption/lib/Controller/SettingsController.php index 8548ea51c04..fd3637e0d79 100644 --- a/apps/encryption/lib/Controller/SettingsController.php +++ b/apps/encryption/lib/Controller/SettingsController.php @@ -37,7 +37,7 @@ class SettingsController extends Controller { * @param Util $util */ public function __construct( - $AppName, + $appName, IRequest $request, private IL10N $l, private IUserManager $userManager, @@ -48,7 +48,7 @@ class SettingsController extends Controller { private ISession $ocSession, private Util $util, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } diff --git a/apps/encryption/lib/Controller/StatusController.php b/apps/encryption/lib/Controller/StatusController.php index 341ad6bc49f..914432f78a3 100644 --- a/apps/encryption/lib/Controller/StatusController.php +++ b/apps/encryption/lib/Controller/StatusController.php @@ -25,13 +25,13 @@ class StatusController extends Controller { * @param IManager $encryptionManager */ public function __construct( - $AppName, + $appName, IRequest $request, private IL10N $l, private Session $session, private IManager $encryptionManager, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/federation/lib/Controller/SettingsController.php b/apps/federation/lib/Controller/SettingsController.php index 27341eba815..541c821d569 100644 --- a/apps/federation/lib/Controller/SettingsController.php +++ b/apps/federation/lib/Controller/SettingsController.php @@ -22,13 +22,13 @@ use Psr\Log\LoggerInterface; class SettingsController extends OCSController { public function __construct( - string $AppName, + string $appName, IRequest $request, private IL10N $l, private TrustedServers $trustedServers, private LoggerInterface $logger, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index e7274c9cfb6..0f9326ef464 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -36,7 +36,7 @@ class GlobalStoragesController extends StoragesController { * @param IConfig $config */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, GlobalStoragesService $globalStoragesService, @@ -46,7 +46,7 @@ class GlobalStoragesController extends StoragesController { IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $globalStoragesService, diff --git a/apps/files_external/lib/Controller/StoragesController.php b/apps/files_external/lib/Controller/StoragesController.php index df3a4528054..cf3fbc2d24f 100644 --- a/apps/files_external/lib/Controller/StoragesController.php +++ b/apps/files_external/lib/Controller/StoragesController.php @@ -40,7 +40,7 @@ abstract class StoragesController extends Controller { * @param LoggerInterface $logger */ public function __construct( - $AppName, + $appName, IRequest $request, protected IL10N $l10n, protected StoragesService $service, @@ -49,7 +49,7 @@ abstract class StoragesController extends Controller { protected IGroupManager $groupManager, protected IConfig $config, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/files_external/lib/Controller/UserGlobalStoragesController.php b/apps/files_external/lib/Controller/UserGlobalStoragesController.php index 88a9f936401..d1f231a870f 100644 --- a/apps/files_external/lib/Controller/UserGlobalStoragesController.php +++ b/apps/files_external/lib/Controller/UserGlobalStoragesController.php @@ -42,7 +42,7 @@ class UserGlobalStoragesController extends StoragesController { * @param IGroupManager $groupManager */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, UserGlobalStoragesService $userGlobalStoragesService, @@ -52,7 +52,7 @@ class UserGlobalStoragesController extends StoragesController { IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $userGlobalStoragesService, diff --git a/apps/files_external/lib/Controller/UserStoragesController.php b/apps/files_external/lib/Controller/UserStoragesController.php index 7b564d57f7e..f724718aaa5 100644 --- a/apps/files_external/lib/Controller/UserStoragesController.php +++ b/apps/files_external/lib/Controller/UserStoragesController.php @@ -39,7 +39,7 @@ class UserStoragesController extends StoragesController { * @param IGroupManager $groupManager */ public function __construct( - $AppName, + $appName, IRequest $request, IL10N $l10n, UserStoragesService $userStoragesService, @@ -49,7 +49,7 @@ class UserStoragesController extends StoragesController { IConfig $config, ) { parent::__construct( - $AppName, + $appName, $request, $l10n, $userStoragesService, diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 960f29224bb..abb72793bc0 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -240,8 +240,8 @@ class ApiTest extends TestCase { /** * @group RoutingWeirdness - * @dataProvider dataAllowFederationOnPublicShares */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataAllowFederationOnPublicShares')] public function testCreateShareLinkPublicUpload(array $appConfig, int $permissions): void { $this->appConfig->method('getValueBool') ->willReturnMap([$appConfig]); @@ -1016,8 +1016,8 @@ class ApiTest extends TestCase { /** * @medium - * @dataProvider dataAllowFederationOnPublicShares */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataAllowFederationOnPublicShares')] public function testUpdateShareUpload(array $appConfig, int $permissions): void { $this->appConfig->method('getValueBool')->willReturnMap([ $appConfig, diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index bbdf0b899bd..9a2186d79a4 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -19,6 +19,7 @@ use OCP\IAppConfig; use OCP\IUser; use OCP\IUserManager; use OCP\Lock\ILockingProvider; +use OCP\Lock\LockedException; use Psr\Log\LoggerInterface; class ExpireTrash extends TimedJob { @@ -111,7 +112,7 @@ class ExpireTrash extends TimedJob { } private function resetOffset() { - $this->runMutexOperation(function () { + $this->runMutexOperation(function (): void { $this->appConfig->setValueInt(Application::APP_ID, self::OFFSET_CONFIG_KEY_NAME, 0); }); } @@ -123,7 +124,7 @@ class ExpireTrash extends TimedJob { try { $this->lockingProvider->acquireLock(self::OFFSET_CONFIG_KEY_NAME, ILockingProvider::LOCK_EXCLUSIVE, 'Expire trashbin background job offset'); $acquired = true; - } catch (\OCP\Lock\LockedException $e) { + } catch (LockedException $e) { // wait a bit and try again usleep(100000); } diff --git a/apps/files_trashbin/tests/Command/ExpireTrashTest.php b/apps/files_trashbin/tests/Command/ExpireTrashTest.php index 0d0ee98ca7a..edad8bfbd95 100644 --- a/apps/files_trashbin/tests/Command/ExpireTrashTest.php +++ b/apps/files_trashbin/tests/Command/ExpireTrashTest.php @@ -64,9 +64,7 @@ class ExpireTrashTest extends TestCase { parent::tearDown(); } - /** - * @dataProvider retentionObligationProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('retentionObligationProvider')] public function testRetentionObligation(string $obligation, string $quota, int $elapsed, int $fileSize, bool $shouldExpire): void { $this->config->setSystemValues(['trashbin_retention_obligation' => $obligation]); $this->expiration->setRetentionObligation($obligation); diff --git a/apps/settings/lib/Controller/AuthorizedGroupController.php b/apps/settings/lib/Controller/AuthorizedGroupController.php index 82a1ca4703e..9ff0f2cb215 100644 --- a/apps/settings/lib/Controller/AuthorizedGroupController.php +++ b/apps/settings/lib/Controller/AuthorizedGroupController.php @@ -16,11 +16,11 @@ use OCP\IRequest; class AuthorizedGroupController extends Controller { public function __construct( - string $AppName, + string $appName, IRequest $request, private AuthorizedGroupService $authorizedGroupService, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); } /** diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 82a46bea4fb..3335dede58b 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -31,7 +31,7 @@ class CheckSetupController extends Controller { private $checker; public function __construct( - $AppName, + $appName, IRequest $request, private IConfig $config, private IURLGenerator $urlGenerator, @@ -40,7 +40,7 @@ class CheckSetupController extends Controller { private LoggerInterface $logger, private ISetupCheckManager $setupCheckManager, ) { - parent::__construct($AppName, $request); + parent::__construct($appName, $request); $this->checker = $checker; } diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 950aaf92acb..8f95f1415a1 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -71,8 +71,6 @@ authorId]]> authorId]]> authorId]]> - fileId]]> - fileId]]> name]]> path]]> @@ -111,7 +109,6 @@ authorId]]> comment]]> - fileId]]> fileName]]> path]]> diff --git a/build/rector.php b/build/rector.php index 246741bb34f..90b33bad6ff 100644 --- a/build/rector.php +++ b/build/rector.php @@ -77,6 +77,9 @@ $config = RectorConfig::configure() $nextcloudDir . '/apps/*/build/stubs/*', $nextcloudDir . '/apps/*/composer/*', $nextcloudDir . '/apps/*/config/*', + // The mock classes are excluded, as the tests explicitly test the annotations which should not be migrated to attributes + $nextcloudDir . '/tests/lib/AppFramework/Middleware/Mock/*', + $nextcloudDir . '/tests/lib/AppFramework/Middleware/Security/Mock/*', ]) // uncomment to reach your current PHP version // ->withPhpSets() @@ -92,7 +95,7 @@ $config = RectorConfig::configure() 'rename_property' => true, ]) ->withSets([ - NextcloudSets::NEXTCLOUD_25, + NextcloudSets::NEXTCLOUD_27, ]); $config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class); diff --git a/console.php b/console.php index 10de07dd489..b5a000e8873 100644 --- a/console.php +++ b/console.php @@ -3,6 +3,7 @@ declare(strict_types=1); use OCP\IConfig; +use OCP\IURLGenerator; use OCP\Server; /** @@ -100,7 +101,7 @@ try { $profile->setUrl(implode(' ', $argv)); $profiler->saveProfile($profile); - $urlGenerator = Server::get(\OCP\IURLGenerator::class); + $urlGenerator = Server::get(IURLGenerator::class); $url = $urlGenerator->linkToRouteAbsolute('profiler.main.profiler', [ 'profiler' => 'db', 'token' => $profile->getToken(), diff --git a/core/Command/Base.php b/core/Command/Base.php index 8f94c1d473a..138f3ca613b 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -8,6 +8,8 @@ namespace OC\Core\Command; use OC\Core\Command\User\ListCommand; +use OCP\Defaults; +use OCP\Server; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; @@ -27,7 +29,7 @@ class Base extends Command implements CompletionAwareInterface { protected function configure() { // Some of our commands do not extend this class; and some of those that do do not call parent::configure() - $defaultHelp = 'More extensive and thorough documentation may be found at ' . \OCP\Server::get(\OCP\Defaults::class)->getDocBaseUrl() . PHP_EOL; + $defaultHelp = 'More extensive and thorough documentation may be found at ' . Server::get(Defaults::class)->getDocBaseUrl() . PHP_EOL; $this ->setHelp($defaultHelp) ->addOption( diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index 4791139bb12..8072bb8e92a 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\OpenAPI; +use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\StandaloneTemplateResponse; @@ -150,7 +151,6 @@ class TwoFactorChallengeController extends Controller { /** * @TwoFactorSetUpDoneRequired * - * @UserRateThrottle(limit=5, period=100) * * @param string $challengeProviderId * @param string $challenge @@ -161,6 +161,7 @@ class TwoFactorChallengeController extends Controller { #[NoCSRFRequired] #[UseSession] #[FrontpageRoute(verb: 'POST', url: '/login/challenge/{challengeProviderId}')] + #[UserRateLimit(limit: 5, period: 100)] public function solveChallenge($challengeProviderId, $challenge, $redirect_url = null) { $user = $this->userSession->getUser(); $provider = $this->twoFactorManager->getProvider($user, $challengeProviderId); diff --git a/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php b/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php new file mode 100644 index 00000000000..d5ee95dfe4c --- /dev/null +++ b/tests/lib/AppFramework/Middleware/Mock/UseSessionController.php @@ -0,0 +1,19 @@ +method('sleepDelayOrThrowOnMax') ->with('127.0.0.1', 'login'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->beforeController($controller, 'testMethodWithAnnotation'); } @@ -89,7 +68,7 @@ class BruteForceMiddlewareTest extends TestCase { ->method('sleepDelayOrThrowOnMax') ->with('::1', 'single'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'singleAttribute'); $this->bruteForceMiddleware->beforeController($controller, 'singleAttribute'); } @@ -113,7 +92,7 @@ class BruteForceMiddlewareTest extends TestCase { return 0; }); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->beforeController($controller, 'multipleAttributes'); } @@ -126,7 +105,7 @@ class BruteForceMiddlewareTest extends TestCase { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->bruteForceMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } @@ -155,7 +134,7 @@ class BruteForceMiddlewareTest extends TestCase { ->method('registerAttempt') ->with('login', '127.0.0.1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithAnnotation', $response); } @@ -177,7 +156,7 @@ class BruteForceMiddlewareTest extends TestCase { ->expects($this->never()) ->method('registerAttempt'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithAnnotation'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithAnnotation', $response); } @@ -207,7 +186,7 @@ class BruteForceMiddlewareTest extends TestCase { ->method('registerAttempt') ->with('single', '::1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'singleAttribute'); $this->bruteForceMiddleware->afterController($controller, 'singleAttribute', $response); } @@ -254,7 +233,7 @@ class BruteForceMiddlewareTest extends TestCase { $this->assertEquals($expected, func_get_args()); }); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->afterController($controller, 'multipleAttributes', $response); } @@ -284,7 +263,7 @@ class BruteForceMiddlewareTest extends TestCase { ->method('registerAttempt') ->with('second', '::1'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'multipleAttributes'); $this->bruteForceMiddleware->afterController($controller, 'multipleAttributes', $response); } @@ -297,7 +276,7 @@ class BruteForceMiddlewareTest extends TestCase { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); /** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */ $response = $this->createMock(Response::class); @@ -312,7 +291,7 @@ class BruteForceMiddlewareTest extends TestCase { ->expects($this->never()) ->method('sleepDelayOrThrowOnMax'); - $controller = new TestController('test', $this->request); + $controller = new BruteForceMiddlewareController('test', $this->request); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); /** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */ $response = $this->createMock(Response::class); @@ -321,7 +300,7 @@ class BruteForceMiddlewareTest extends TestCase { $this->logger->expects($this->once()) ->method('debug') - ->with('Response for Test\AppFramework\Middleware\Security\TestController::testMethodWithoutAnnotation got bruteforce throttled but has no annotation nor attribute defined.'); + ->with('Response for Test\AppFramework\Middleware\Security\Mock\BruteForceMiddlewareController::testMethodWithoutAnnotation got bruteforce throttled but has no annotation nor attribute defined.'); $this->bruteForceMiddleware->afterController($controller, 'testMethodWithoutAnnotation', $response); } diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php new file mode 100644 index 00000000000..a5091004fcb --- /dev/null +++ b/tests/lib/AppFramework/Middleware/Security/Mock/BruteForceMiddlewareController.php @@ -0,0 +1,26 @@ +method('isLoggedIn') ->willReturn(false); - /** @var TestRateLimitController|MockObject $controller */ - $controller = $this->createMock(TestRateLimitController::class); + /** @var RateLimitingMiddlewareController|MockObject $controller */ + $controller = $this->createMock(RateLimitingMiddlewareController::class); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->rateLimitingMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } @@ -119,14 +90,14 @@ class RateLimitingMiddlewareTest extends TestCase { ->method('isLoggedIn') ->willReturn(true); - /** @var TestRateLimitController|MockObject $controller */ - $controller = $this->createMock(TestRateLimitController::class); + /** @var RateLimitingMiddlewareController|MockObject $controller */ + $controller = $this->createMock(RateLimitingMiddlewareController::class); $this->reflector->reflect($controller, 'testMethodWithoutAnnotation'); $this->rateLimitingMiddleware->beforeController($controller, 'testMethodWithoutAnnotation'); } public function testBeforeControllerForAnon(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->method('getRemoteAddress') @@ -150,7 +121,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testBeforeControllerForLoggedIn(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); /** @var IUser|MockObject $user */ $user = $this->createMock(IUser::class); @@ -177,7 +148,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testBeforeControllerAnonWithFallback(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getRemoteAddress') @@ -202,7 +173,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testBeforeControllerAttributesForAnon(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->method('getRemoteAddress') @@ -226,7 +197,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testBeforeControllerAttributesForLoggedIn(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); /** @var IUser|MockObject $user */ $user = $this->createMock(IUser::class); @@ -253,7 +224,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testBeforeControllerAttributesAnonWithFallback(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getRemoteAddress') @@ -281,13 +252,13 @@ class RateLimitingMiddlewareTest extends TestCase { $this->expectException(\Exception::class); $this->expectExceptionMessage('My test exception'); - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new \Exception('My test exception')); } public function testAfterExceptionWithJsonBody(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getHeader') @@ -301,7 +272,7 @@ class RateLimitingMiddlewareTest extends TestCase { } public function testAfterExceptionWithHtmlBody(): void { - $controller = new TestRateLimitController('test', $this->request); + $controller = new RateLimitingMiddlewareController('test', $this->request); $this->request ->expects($this->once()) ->method('getHeader') diff --git a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php index 8ecc73791c9..234696ddcf1 100644 --- a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php @@ -11,11 +11,11 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Middleware\SessionMiddleware; use OC\AppFramework\Utility\ControllerMethodReflector; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\Response; use OCP\IRequest; use OCP\ISession; use PHPUnit\Framework\MockObject\MockObject; +use Test\AppFramework\Middleware\Mock\UseSessionController; use Test\TestCase; class SessionMiddlewareTest extends TestCase { @@ -29,18 +29,7 @@ class SessionMiddlewareTest extends TestCase { $this->reflector = $this->createMock(ControllerMethodReflector::class); $this->session = $this->createMock(ISession::class); - $this->controller = new class('app', $this->createMock(IRequest::class)) extends Controller { - /** - * @UseSession - */ - public function withAnnotation() { - } - #[UseSession] - public function withAttribute() { - } - public function without() { - } - }; + $this->controller = new UseSessionController('app', $this->createMock(IRequest::class)); $this->middleware = new SessionMiddleware( $this->reflector, $this->session, diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index a2107a7491f..a1c3ae3d905 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -189,7 +189,7 @@ class QueryBuilderTest extends \Test\TestCase { array_walk_recursive( $selectArguments, - function (string &$arg) { + function (string &$arg): void { if (\str_starts_with($arg, 'l::')) { $arg = $this->queryBuilder->expr()->literal(substr($arg, 3)); } @@ -357,7 +357,7 @@ class QueryBuilderTest extends \Test\TestCase { array_walk_recursive( $selectArguments, - function (string &$arg) { + function (string &$arg): void { if (\str_starts_with($arg, 'l::')) { $arg = $this->queryBuilder->expr()->literal(substr($arg, 3)); } diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index ed51dd3ffd6..e459b81512d 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -212,7 +212,7 @@ class SystemTagObjectMapperTest extends TestCase { public function testAssignUnassignTags(): void { $event = null; - $this->dispatcher->expects($this->any())->method('dispatchTyped')->willReturnCallback(function (Event $e) use (&$event) { + $this->dispatcher->expects($this->any())->method('dispatchTyped')->willReturnCallback(function (Event $e) use (&$event): void { $event = $e; });