diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 65fac15646080..3ebc3f48a7085 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -1811,23 +1811,6 @@ private function getDeckShareHelper() { return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper'); } - /** - * Returns the helper of ShareAPIHelper for sciencemesh shares. - * - * If the sciencemesh application is not enabled or the helper is not available - * a ContainerExceptionInterface is thrown instead. - * - * @return ShareAPIHelper - * @throws ContainerExceptionInterface - */ - private function getSciencemeshShareHelper() { - if (!$this->appManager->isEnabledForUser('sciencemesh')) { - throw new QueryException(); - } - - return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper'); - } - /** * @param string $viewer * @param Node $node diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index c06b702764f4a..446ac4c7bb586 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -12,7 +12,6 @@ use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Manager; use OCP\App\IAppManager; -use OCP\AppFramework\QueryException; use OCP\AppFramework\Services\IAppConfig; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; @@ -37,6 +36,7 @@ use OCP\WorkflowEngine\IRuleMatcher; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -327,7 +327,7 @@ public function testGetOperations(): void { case 'OCA\WFE\TestOp': return $operation; case 'OCA\WFE\OtherTestOp': - throw new QueryException(); + throw $this->createMock(ContainerExceptionInterface::class); } }); diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 9912e2c901337..7e27b134f5ce5 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -15,7 +15,6 @@ use OCP\App\IAppManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootstrap; -use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; @@ -166,7 +165,7 @@ public function bootApp(string $appId): void { $context = new BootContext($application->getContainer()); $application->boot($context); } - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ 'exception' => $e, ]); diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 28580065dfdde..d288eb7d13744 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -66,6 +66,7 @@ use OCP\L10N\IFactory; use OCP\Security\Ip\IRemoteAddress; use OCP\Server; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -342,12 +343,12 @@ public function query(string $name, bool $autoload = true, array $chain = []): m try { return $this->queryNoFallback($name, $chain); - } catch (QueryException $firstException) { + } catch (ContainerExceptionInterface $firstException) { try { /** @var ServerContainer $server */ $server = $this->getServer(); return $server->query($name, $autoload, $chain); - } catch (QueryException $secondException) { + } catch (ContainerExceptionInterface $secondException) { if ($firstException->getCode() === 1) { throw $secondException; } @@ -360,7 +361,7 @@ public function query(string $name, bool $autoload = true, array $chain = []): m * @param string $name * @param list $chain * @return mixed - * @throws QueryException if the query could not be resolved + * @throws ContainerExceptionInterface if the query could not be resolved */ public function queryNoFallback($name, array $chain) { $name = $this->sanitizeName($name); diff --git a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php index 66313b1b0a320..05eba715d367f 100644 --- a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php +++ b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php @@ -12,10 +12,10 @@ use Exception; use OC\AppFramework\Bootstrap\Coordinator; use OCP\App\IAppManager; -use OCP\AppFramework\QueryException; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\IUser; use OCP\Server; +use Psr\Container\ContainerExceptionInterface; class ProviderLoader { public const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; @@ -50,7 +50,7 @@ public function getProviders(?IUser $user = null): array { $this->loadTwoFactorApp($appId); $provider = Server::get($class); $providers[$provider->getId()] = $provider; - } catch (QueryException $exc) { + } catch (ContainerExceptionInterface $exc) { // Provider class can not be resolved throw new Exception("Could not load two-factor auth provider $class"); } @@ -64,7 +64,7 @@ public function getProviders(?IUser $user = null): array { $this->loadTwoFactorApp($provider->getAppId()); $providerInstance = Server::get($provider->getService()); $providers[$providerInstance->getId()] = $providerInstance; - } catch (QueryException $exc) { + } catch (ContainerExceptionInterface $exc) { // Provider class can not be resolved throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); } diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php index cd00e20649d19..0911af124ecb7 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -11,9 +11,9 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\Calendar\ResourcesRoomsUpdater; -use OCP\AppFramework\QueryException; use OCP\Calendar\Resource\IBackend; use OCP\Calendar\Resource\IManager; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; class Manager implements IManager { @@ -73,7 +73,7 @@ private function fetchBootstrapBackends(): void { /** * @return IBackend[] - * @throws QueryException + * @throws ContainerExceptionInterface * @since 14.0.0 */ #[\Override] @@ -93,7 +93,7 @@ public function getBackends():array { /** * @param string $backendId - * @throws QueryException + * @throws ContainerExceptionInterface */ #[\Override] public function getBackend($backendId): ?IBackend { diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php index 76de5eb34a73c..9eb64af78ca9a 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -11,9 +11,9 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\Calendar\ResourcesRoomsUpdater; -use OCP\AppFramework\QueryException; use OCP\Calendar\Room\IBackend; use OCP\Calendar\Room\IManager; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; class Manager implements IManager { @@ -74,7 +74,7 @@ private function fetchBootstrapBackends(): void { /** * @return IBackend[] - * @throws QueryException + * @throws ContainerExceptionInterface * @since 14.0.0 */ #[\Override] @@ -100,7 +100,7 @@ public function getBackends():array { /** * @param string $backendId - * @throws QueryException + * @throws ContainerExceptionInterface */ #[\Override] public function getBackend($backendId): ?IBackend { diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php index 9e9db13a89bed..09c6068d266bf 100644 --- a/lib/private/CapabilitiesManager.php +++ b/lib/private/CapabilitiesManager.php @@ -9,11 +9,11 @@ namespace OC; -use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IInitialStateExcludedCapability; use OCP\Capabilities\IPublicCapability; use OCP\ILogger; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; class CapabilitiesManager { @@ -44,7 +44,7 @@ public function getCapabilities(bool $public = false, bool $initialState = false foreach ($this->capabilities as $capability) { try { $c = $capability(); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->error('CapabilitiesManager', [ 'exception' => $e, ]); diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index fefc7722a2f7b..ae8b2aea7df31 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -7,13 +7,13 @@ namespace OC\Collaboration\Collaborators; -use OCP\AppFramework\QueryException; use OCP\Collaboration\Collaborators\ISearch; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\IContainer; use OCP\Share\IShare; +use Psr\Container\ContainerExceptionInterface; class Search implements ISearch { protected array $pluginList = []; @@ -28,7 +28,7 @@ public function __construct( * @param bool $lookup * @param int|null $limit * @param int|null $offset - * @throws QueryException + * @throws ContainerExceptionInterface */ #[\Override] public function search($search, array $shareTypes, $lookup, $limit, $offset): array { diff --git a/lib/private/Collaboration/Resources/ProviderManager.php b/lib/private/Collaboration/Resources/ProviderManager.php index a73a383ac302c..df2ebfb33da7e 100644 --- a/lib/private/Collaboration/Resources/ProviderManager.php +++ b/lib/private/Collaboration/Resources/ProviderManager.php @@ -9,9 +9,9 @@ namespace OC\Collaboration\Resources; -use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IProviderManager; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -34,7 +34,7 @@ public function getResourceProviders(): array { foreach ($this->providers as $provider) { try { $this->providerInstances[] = $this->serverContainer->get($provider); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ 'exception' => $e, ]); diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php index 4606c1cce1a8f..27e00df7c5031 100644 --- a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php +++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php @@ -14,10 +14,10 @@ use OC\Contacts\ContactsMenu\Providers\EMailProvider; use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider; use OC\Contacts\ContactsMenu\Providers\ProfileProvider; -use OCP\AppFramework\QueryException; use OCP\Contacts\ContactsMenu\IBulkProvider; use OCP\Contacts\ContactsMenu\IProvider; use OCP\IUser; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -50,7 +50,7 @@ public function getProviders(IUser $user): array { 'class' => $class, ]); } - } catch (QueryException $ex) { + } catch (ContainerExceptionInterface $ex) { $this->logger->error( 'Could not load contacts menu action provider ' . $class, [ diff --git a/lib/private/EventDispatcher/ServiceEventListener.php b/lib/private/EventDispatcher/ServiceEventListener.php index f9cc85b412605..dc6c65a3b6c63 100644 --- a/lib/private/EventDispatcher/ServiceEventListener.php +++ b/lib/private/EventDispatcher/ServiceEventListener.php @@ -9,9 +9,9 @@ namespace OC\EventDispatcher; -use OCP\AppFramework\QueryException; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use function sprintf; @@ -39,7 +39,7 @@ public function __invoke(Event $event) { // parameters and aliases won't be resolved. // See https://github.com/nextcloud/server/issues/27793 for details. $this->service = $this->container->get($this->class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->error( sprintf( 'Could not load event listener service %s: %s. Make sure the class is auto-loadable by the Nextcloud server container', diff --git a/lib/private/Http/WellKnown/RequestManager.php b/lib/private/Http/WellKnown/RequestManager.php index e4ff5c03b7360..665152cb99f6a 100644 --- a/lib/private/Http/WellKnown/RequestManager.php +++ b/lib/private/Http/WellKnown/RequestManager.php @@ -11,12 +11,12 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\AppFramework\Bootstrap\ServiceRegistration; -use OCP\AppFramework\QueryException; use OCP\Http\WellKnown\IHandler; use OCP\Http\WellKnown\IRequestContext; use OCP\Http\WellKnown\IResponse; use OCP\Http\WellKnown\JrdResponse; use OCP\IRequest; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use RuntimeException; @@ -85,7 +85,7 @@ private function loadHandlers(): array { } return $handler; - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->logger->error("Could not load well known handler $class", [ 'exception' => $e, 'app' => $registration->getAppId(), diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php index e00f755502105..8eacda01dc7c4 100644 --- a/lib/private/InitialStateService.php +++ b/lib/private/InitialStateService.php @@ -11,9 +11,9 @@ use Closure; use OC\AppFramework\Bootstrap\Coordinator; -use OCP\AppFramework\QueryException; use OCP\AppFramework\Services\InitialStateProvider; use OCP\IInitialStateService; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -94,8 +94,8 @@ private function loadLazyStates(): void { $initialStates = $context->getInitialStates(); foreach ($initialStates as $initialState) { try { - $provider = $this->container->query($initialState->getService()); - } catch (QueryException $e) { + $provider = $this->container->get($initialState->getService()); + } catch (ContainerExceptionInterface $e) { // Log an continue. We can be fault tolerant here. $this->logger->error('Could not load initial state provider dynamically: ' . $e->getMessage(), [ 'exception' => $e, diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 94e2ce13f16a0..b780b204c21d4 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -13,6 +13,7 @@ use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Utility\SimpleContainer; use OCP\AppFramework\QueryException; +use Psr\Container\ContainerExceptionInterface; use function explode; use function strtolower; @@ -60,7 +61,7 @@ public function registerAppContainer(string $appName, DIContainer $container): v /** * @param string $appName * @return DIContainer - * @throws QueryException + * @throws ContainerExceptionInterface */ public function getRegisteredAppContainer(string $appName): DIContainer { if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName))])) { @@ -74,7 +75,7 @@ public function getRegisteredAppContainer(string $appName): DIContainer { * @param string $namespace * @param string $sensitiveNamespace * @return DIContainer - * @throws QueryException + * @throws ContainerExceptionInterface */ protected function getAppContainer(string $sensitiveNamespace): DIContainer { $namespace = strtolower($sensitiveNamespace); @@ -119,7 +120,7 @@ public function has($id, bool $noRecursion = false): bool { * @psalm-template S as class-string|string * @psalm-param S $name * @psalm-return (S is class-string ? T : mixed) - * @throws QueryException + * @throws ContainerExceptionInterface * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get */ #[\Override] @@ -130,7 +131,7 @@ public function query(string $name, bool $autoload = true, array $chain = []): m // Skip server container query for app namespace classes try { return parent::query($name, false, $chain); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { // Continue with general autoloading then } // In case the service starts with OCA\ we try to find the service in @@ -138,7 +139,7 @@ public function query(string $name, bool $autoload = true, array $chain = []): m if (($appContainer = $this->getAppContainerForService($name)) !== null) { try { return $appContainer->queryNoFallback($name, $chain); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { // Didn't find the service or the respective app container // In this case the service won't be part of the core container, // so we can throw directly @@ -163,7 +164,7 @@ public function getAppContainerForService(string $id): ?DIContainer { try { [,$namespace,] = explode('\\', $id, 3); return $this->getAppContainer('OCA\\' . $namespace); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { return null; } } diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 34c097b9f3063..bf7200dd78370 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -8,7 +8,6 @@ namespace OC\Settings; use Closure; -use OCP\AppFramework\QueryException; use OCP\Group\ISubAdmin; use OCP\IGroupManager; use OCP\IL10N; @@ -20,6 +19,7 @@ use OCP\Settings\IManager; use OCP\Settings\ISettings; use OCP\Settings\ISubAdminSettings; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -79,7 +79,7 @@ protected function getSections(string $type): array { try { /** @var IIconSection $section */ $section = $this->container->get($class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->log->info($e->getMessage(), ['exception' => $e]); continue; } @@ -148,7 +148,7 @@ protected function getSettings(string $type, string $section, ?Closure $filter = try { /** @var ISettings $setting */ $setting = $this->container->get($class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { $this->log->info($e->getMessage(), ['exception' => $e]); continue; } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 7f598f7abc843..cbc831e4c2f9f 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -31,7 +31,6 @@ use OC\User\BackgroundJobs\CleanupDeletedUsers; use OC\User\BackgroundJobs\CleanupLoginTokens; use OC\User\Session; -use OCP\AppFramework\QueryException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\Defaults; @@ -54,6 +53,7 @@ use OCP\Server; use OCP\ServerVersion; use OCP\Util; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; class Setup { @@ -571,7 +571,7 @@ private static function findWebRoot(SystemConfig $config): string { /** * Append the correct ErrorDocument path for Apache hosts * - * @throws QueryException + * @throws ContainerExceptionInterface */ public static function updateHtaccess(): bool { $config = Server::get(SystemConfig::class); diff --git a/lib/private/Support/CrashReport/Registry.php b/lib/private/Support/CrashReport/Registry.php index 21acbcc810b28..237bb6ca75a38 100644 --- a/lib/private/Support/CrashReport/Registry.php +++ b/lib/private/Support/CrashReport/Registry.php @@ -10,12 +10,12 @@ namespace OC\Support\CrashReport; use Exception; -use OCP\AppFramework\QueryException; use OCP\Server; use OCP\Support\CrashReport\ICollectBreadcrumbs; use OCP\Support\CrashReport\IMessageReporter; use OCP\Support\CrashReport\IRegistry; use OCP\Support\CrashReport\IReporter; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; use Throwable; use function array_shift; @@ -90,7 +90,7 @@ private function loadLazyProviders(): void { try { /** @var IReporter $reporter */ $reporter = Server::get($class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { /* * There is a circular dependency between the logger and the registry, so * we can not inject it. Thus the static call. diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 1aea82dd50d6e..abacb29bf595b 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -17,11 +17,11 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -69,7 +69,7 @@ public function testBootAppNotLoadable(): void { $this->serverContainer->expects($this->once()) ->method('get') ->with(Application::class) - ->willThrowException(new QueryException('')); + ->willThrowException($this->createMock(ContainerExceptionInterface::class)); $this->logger->expects($this->once()) ->method('error'); diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php index 128059d275559..c7994147fe772 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php +++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php @@ -17,10 +17,10 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\Security\SecurityMiddleware; use OCP\AppFramework\Middleware; -use OCP\AppFramework\QueryException; use OCP\IConfig; use OCP\IRequestId; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; #[\PHPUnit\Framework\Attributes\Group('DB')] class DIContainerTest extends \Test\TestCase { @@ -137,7 +137,7 @@ public function testMiddlewareDispatcherIncludesGlobalBootstrapMiddlewares(): vo } public function testInvalidAppClass(): void { - $this->expectException(QueryException::class); - $this->container->query('\OCA\Name\Foo'); + $this->expectException(ContainerExceptionInterface::class); + $this->container->get('\OCA\Name\Foo'); } } diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php index 6ad23c9506c81..e152698125b42 100644 --- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php +++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php @@ -11,7 +11,7 @@ namespace Test\AppFramework\Utility; use OC\AppFramework\Utility\SimpleContainer; -use OCP\AppFramework\QueryException; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; interface TestInterface { @@ -70,55 +70,55 @@ protected function setUp(): void { public function testRegister(): void { $this->container->registerParameter('test', 'abc'); - $this->assertEquals('abc', $this->container->query('test')); + $this->assertEquals('abc', $this->container->get('test')); } /** - * Test querying a class that is not registered without autoload enabled + * Test geting a class that is not registered without autoload enabled */ public function testNothingRegistered(): void { try { - $this->container->query('something really hard', false); + $this->container->get('something really hard', false); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(QueryException::class, $exception); + $this->assertInstanceOf(ContainerExceptionInterface::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } /** - * Test querying a class that is not registered with autoload enabled + * Test geting a class that is not registered with autoload enabled */ public function testNothingRegistered_autoload(): void { try { - $this->container->query('something really hard'); + $this->container->get('something really hard'); $this->fail('Expected `QueryException` exception was not thrown'); } catch (\Throwable $exception) { - $this->assertInstanceOf(QueryException::class, $exception); + $this->assertInstanceOf(ContainerExceptionInterface::class, $exception); $this->assertInstanceOf(NotFoundExceptionInterface::class, $exception); } } public function testNotAClass(): void { - $this->expectException(QueryException::class); + $this->expectException(ContainerExceptionInterface::class); - $this->container->query('Test\AppFramework\Utility\TestInterface'); + $this->container->get('Test\AppFramework\Utility\TestInterface'); } public function testNoConstructorClass(): void { - $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); + $object = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor'); $this->assertTrue($object instanceof ClassEmptyConstructor); } public function testInstancesOnlyOnce(): void { - $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); - $object2 = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor'); + $object = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor'); + $object2 = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor'); $this->assertSame($object, $object2); } public function testConstructorSimple(): void { $this->container->registerParameter('test', 'abc'); - $object = $this->container->query( + $object = $this->container->get( 'Test\AppFramework\Utility\ClassSimpleConstructor' ); $this->assertTrue($object instanceof ClassSimpleConstructor); @@ -127,7 +127,7 @@ public function testConstructorSimple(): void { public function testConstructorComplex(): void { $this->container->registerParameter('test', 'abc'); - $object = $this->container->query( + $object = $this->container->get( 'Test\AppFramework\Utility\ClassComplexConstructor' ); $this->assertTrue($object instanceof ClassComplexConstructor); @@ -139,9 +139,9 @@ public function testConstructorComplexInterface(): void { $this->container->registerParameter('test', 'abc'); $this->container->registerService( 'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) { - return $c->query('Test\AppFramework\Utility\ClassSimpleConstructor'); + return $c->get('Test\AppFramework\Utility\ClassSimpleConstructor'); }); - $object = $this->container->query( + $object = $this->container->get( 'Test\AppFramework\Utility\ClassInterfaceConstructor' ); $this->assertTrue($object instanceof ClassInterfaceConstructor); @@ -152,13 +152,13 @@ public function testConstructorComplexInterface(): void { public function testOverrideService(): void { $this->container->registerService( 'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) { - return $c->query('Test\AppFramework\Utility\ClassSimpleConstructor'); + return $c->get('Test\AppFramework\Utility\ClassSimpleConstructor'); }); $this->container->registerService( 'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) { - return $c->query('Test\AppFramework\Utility\ClassEmptyConstructor'); + return $c->get('Test\AppFramework\Utility\ClassEmptyConstructor'); }); - $object = $this->container->query( + $object = $this->container->get( 'Test\AppFramework\Utility\IInterfaceConstructor' ); $this->assertTrue($object instanceof ClassEmptyConstructor); @@ -167,7 +167,7 @@ public function testOverrideService(): void { public function testRegisterAliasParamter(): void { $this->container->registerParameter('test', 'abc'); $this->container->registerAlias('test1', 'test'); - $this->assertEquals('abc', $this->container->query('test1')); + $this->assertEquals('abc', $this->container->get('test1')); } public function testRegisterAliasService(): void { @@ -176,11 +176,11 @@ public function testRegisterAliasService(): void { }, true); $this->container->registerAlias('test1', 'test'); $this->assertSame( - $this->container->query('test'), $this->container->query('test')); + $this->container->get('test'), $this->container->get('test')); $this->assertSame( - $this->container->query('test1'), $this->container->query('test1')); + $this->container->get('test1'), $this->container->get('test1')); $this->assertSame( - $this->container->query('test'), $this->container->query('test1')); + $this->container->get('test'), $this->container->get('test1')); } public static function sanitizeNameProvider(): array { @@ -193,17 +193,17 @@ public static function sanitizeNameProvider(): array { } #[\PHPUnit\Framework\Attributes\DataProvider('sanitizeNameProvider')] - public function testSanitizeName($register, $query): void { + public function testSanitizeName($register, $get): void { $this->container->registerService($register, function () { return 'abc'; }); - $this->assertEquals('abc', $this->container->query($query)); + $this->assertEquals('abc', $this->container->get($get)); } public function testConstructorComplexNoTestParameterFound(): void { - $this->expectException(QueryException::class); + $this->expectException(ContainerExceptionInterface::class); - $object = $this->container->query( + $object = $this->container->get( 'Test\AppFramework\Utility\ClassComplexConstructor' ); /* Use the object to trigger DI on PHP >= 8.4 */ @@ -215,7 +215,7 @@ public function testRegisterFactory(): void { return new \StdClass(); }, false); $this->assertNotSame( - $this->container->query('test'), $this->container->query('test')); + $this->container->get('test'), $this->container->get('test')); } public function testRegisterAliasFactory(): void { @@ -224,17 +224,17 @@ public function testRegisterAliasFactory(): void { }, false); $this->container->registerAlias('test1', 'test'); $this->assertNotSame( - $this->container->query('test'), $this->container->query('test')); + $this->container->get('test'), $this->container->get('test')); $this->assertNotSame( - $this->container->query('test1'), $this->container->query('test1')); + $this->container->get('test1'), $this->container->get('test1')); $this->assertNotSame( - $this->container->query('test'), $this->container->query('test1')); + $this->container->get('test'), $this->container->get('test1')); } public function testQueryUntypedNullable(): void { - $this->expectException(QueryException::class); + $this->expectException(ContainerExceptionInterface::class); - $object = $this->container->query( + $object = $this->container->get( ClassNullableUntypedConstructorArg::class ); /* Use the object to trigger DI on PHP >= 8.4 */ @@ -243,7 +243,7 @@ public function testQueryUntypedNullable(): void { public function testQueryTypedNullable(): void { /** @var ClassNullableTypedConstructorArg $service */ - $service = $this->container->query(ClassNullableTypedConstructorArg::class); + $service = $this->container->get(ClassNullableTypedConstructorArg::class); self::assertNull($service->class); } diff --git a/tests/lib/CapabilitiesManagerTest.php b/tests/lib/CapabilitiesManagerTest.php index e7b84e6b82f99..7de227aab078a 100644 --- a/tests/lib/CapabilitiesManagerTest.php +++ b/tests/lib/CapabilitiesManagerTest.php @@ -9,9 +9,9 @@ namespace Test; use OC\CapabilitiesManager; -use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IPublicCapability; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; class CapabilitiesManagerTest extends TestCase { @@ -132,7 +132,7 @@ public function testDeepIdenticalCapabilities(): void { public function testInvalidCapability(): void { $this->manager->registerCapability(function (): void { - throw new QueryException(); + throw $this->createMock(ContainerExceptionInterface::class); }); $this->logger->expects($this->once()) diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index f76906534da2b..818807b30e0f8 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -10,8 +10,8 @@ use OC\Collaboration\Resources\ProviderManager; use OCA\Files\Collaboration\Resources\ResourceProvider; -use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProviderManager; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -64,7 +64,7 @@ public function testGetResourceProvidersInvalidProvider(): void { $this->serverContainer->expects($this->once()) ->method('get') ->with($this->equalTo('InvalidResourceProvider')) - ->willThrowException(new QueryException('A meaningful error message')); + ->willThrowException($this->createMock(ContainerExceptionInterface::class)); $this->logger->expects($this->once()) ->method('error'); @@ -80,7 +80,7 @@ public function testGetResourceProvidersValidAndInvalidProvider(): void { ->method('get') ->willReturnCallback(function (string $service) { if ($service === 'InvalidResourceProvider') { - throw new QueryException('A meaningful error message'); + throw $this->createMock(ContainerExceptionInterface::class); } if ($service === ResourceProvider::class) { return $this->createMock(ResourceProvider::class); diff --git a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php index 08afc6e930786..700adecb3c18c 100644 --- a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php @@ -13,10 +13,10 @@ use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider; use OC\Contacts\ContactsMenu\Providers\ProfileProvider; use OCP\App\IAppManager; -use OCP\AppFramework\QueryException; use OCP\Contacts\ContactsMenu\IProvider; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -113,7 +113,7 @@ public function testGetProvidersWithQueryException(): void { ->willReturn([]); $this->serverContainer->expects($this->once()) ->method('get') - ->willThrowException(new QueryException()); + ->willThrowException($this->createMock(ContainerExceptionInterface::class)); $this->actionProviderStore->getProviders($user); } diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index e39ba0b78c62c..20f4c9d63aa8d 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -11,7 +11,6 @@ namespace Test\DB\QueryBuilder; use Doctrine\DBAL\Query\Expression\CompositeExpression; -use Doctrine\DBAL\Query\QueryException; use OC\DB\ConnectionAdapter; use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\Parameter; @@ -23,6 +22,7 @@ use OCP\Server; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; /** @@ -1394,7 +1394,7 @@ public function testExecuteWithParameterTooLarge(): void { ->expects($this->once()) ->method('error') ->willReturnCallback(function ($message, $parameters): void { - $this->assertInstanceOf(QueryException::class, $parameters['exception']); + $this->assertInstanceOf(ContainerExceptionInterface::class, $parameters['exception']); $this->assertSame( 'More than 1000 expressions in a list are not allowed on Oracle.', $message @@ -1433,7 +1433,7 @@ public function testExecuteWithParametersTooMany(): void { ->expects($this->once()) ->method('error') ->willReturnCallback(function ($message, $parameters): void { - $this->assertInstanceOf(QueryException::class, $parameters['exception']); + $this->assertInstanceOf(ContainerExceptionInterface::class, $parameters['exception']); $this->assertSame( 'The number of parameters must not exceed 65535. Restriction by PostgreSQL.', $message diff --git a/tests/lib/Http/WellKnown/RequestManagerTest.php b/tests/lib/Http/WellKnown/RequestManagerTest.php index fc6e721a6166f..4ddc26d562a66 100644 --- a/tests/lib/Http/WellKnown/RequestManagerTest.php +++ b/tests/lib/Http/WellKnown/RequestManagerTest.php @@ -13,13 +13,13 @@ use OC\AppFramework\Bootstrap\RegistrationContext; use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Http\WellKnown\RequestManager; -use OCP\AppFramework\QueryException; use OCP\Http\WellKnown\IHandler; use OCP\Http\WellKnown\IRequestContext; use OCP\Http\WellKnown\IResponse; use OCP\Http\WellKnown\JrdResponse; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use RuntimeException; @@ -85,7 +85,7 @@ public function testProcessHandlerNotLoadable(): void { $this->container->expects(self::once()) ->method('get') ->with(get_class($handler)) - ->willThrowException(new QueryException('')); + ->willThrowException($this->createMock(ContainerExceptionInterface::class)); $this->logger->expects(self::once()) ->method('error'); diff --git a/tests/lib/Talk/BrokerTest.php b/tests/lib/Talk/BrokerTest.php index 8fdf2f50f1ae3..bcbc7d14e082a 100644 --- a/tests/lib/Talk/BrokerTest.php +++ b/tests/lib/Talk/BrokerTest.php @@ -13,10 +13,10 @@ use OC\AppFramework\Bootstrap\RegistrationContext; use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Talk\Broker; -use OCP\AppFramework\QueryException; use OCP\Talk\IConversationOptions; use OCP\Talk\ITalkBackend; use PHPUnit\Framework\Attributes\DataProvider; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use RuntimeException; @@ -73,7 +73,7 @@ public function testHasFaultyBackend(): void { ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); $this->container->expects($this->once()) ->method('get') - ->willThrowException(new QueryException()); + ->willThrowException($this->createMock(ContainerExceptionInterface::class)); $this->logger->expects($this->once()) ->method('error');