From f3ced1c6658345800729dfd343efd794954c6569 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 4 Aug 2026 15:20:13 +0200 Subject: [PATCH 1/2] chore: Port away from QueryException Signed-off-by: Carl Schwan --- lib/Collaboration/Resources/ResourceProvider.php | 4 ++-- lib/Collaboration/Resources/ResourceProviderCard.php | 4 ++-- tests/unit/Service/AttachmentServiceTest.php | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/Collaboration/Resources/ResourceProvider.php b/lib/Collaboration/Resources/ResourceProvider.php index 36ae8f1125..879802c873 100644 --- a/lib/Collaboration/Resources/ResourceProvider.php +++ b/lib/Collaboration/Resources/ResourceProvider.php @@ -12,13 +12,13 @@ use OCA\Deck\Service\PermissionService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; -use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IResource; use OCP\IURLGenerator; use OCP\IUser; use OCP\Server; +use Psr\Container\ContainerExceptionInterface; class ResourceProvider implements IProvider { public const RESOURCE_TYPE = 'deck'; @@ -106,7 +106,7 @@ public function invalidateAccessCache($boardId = null) { try { /** @var IManager $resourceManager */ $resourceManager = Server::get(IManager::class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { } if ($boardId !== null) { $resource = $resourceManager->getResourceForUser(self::RESOURCE_TYPE, (string)$boardId, null); diff --git a/lib/Collaboration/Resources/ResourceProviderCard.php b/lib/Collaboration/Resources/ResourceProviderCard.php index 77c226da95..b58e286972 100644 --- a/lib/Collaboration/Resources/ResourceProviderCard.php +++ b/lib/Collaboration/Resources/ResourceProviderCard.php @@ -14,7 +14,6 @@ use OCA\Deck\Service\PermissionService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; -use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProvider; use OCP\Collaboration\Resources\IResource; @@ -22,6 +21,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\Server; +use Psr\Container\ContainerExceptionInterface; class ResourceProviderCard implements IProvider { public const RESOURCE_TYPE = 'deck-card'; @@ -127,7 +127,7 @@ public function invalidateAccessCache($cardId = null) { try { /** @var IManager $resourceManager */ $resourceManager = Server::get(IManager::class); - } catch (QueryException $e) { + } catch (ContainerExceptionInterface $e) { } if ($cardId !== null) { $resource = $resourceManager->getResourceForUser(self::RESOURCE_TYPE, (string)$cardId, null); diff --git a/tests/unit/Service/AttachmentServiceTest.php b/tests/unit/Service/AttachmentServiceTest.php index 638819073b..8f99bbf235 100644 --- a/tests/unit/Service/AttachmentServiceTest.php +++ b/tests/unit/Service/AttachmentServiceTest.php @@ -98,9 +98,6 @@ class AttachmentServiceTest extends TestCase { */ private $attachmentServiceValidator; - /** - * @throws \OCP\AppFramework\QueryException - */ public function setUp(): void { parent::setUp(); From 48bb80931543194f4d3dd7974a4f3fdabaeb1bfd Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 4 Aug 2026 15:30:27 +0200 Subject: [PATCH 2/2] chore: Port away from IAppContainer Signed-off-by: Carl Schwan --- tests/unit/Service/AttachmentServiceTest.php | 35 +++++++------------ .../Service/BatchQueryPerformanceTest.php | 4 +-- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/tests/unit/Service/AttachmentServiceTest.php b/tests/unit/Service/AttachmentServiceTest.php index 8f99bbf235..89fef6d5f4 100644 --- a/tests/unit/Service/AttachmentServiceTest.php +++ b/tests/unit/Service/AttachmentServiceTest.php @@ -39,10 +39,10 @@ use OCA\Deck\NotFoundException; use OCA\Deck\Validators\AttachmentServiceValidator; use OCP\AppFramework\Http\Response; -use OCP\AppFramework\IAppContainer; use OCP\IL10N; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerInterface; use Test\TestCase; /** @internal Just for testing the service registration */ @@ -104,7 +104,7 @@ public function setUp(): void { $this->attachmentServiceImpl = $this->createMock(IAttachmentService::class); $this->filesAppServiceImpl = $this->createMock(IAttachmentService::class); - $this->appContainer = $this->createMock(IAppContainer::class); + $this->appContainer = $this->createMock(ContainerInterface::class); $this->userManager = $this->createMock(IUserManager::class); $this->attachmentMapper = $this->createMock(AttachmentMapper::class); @@ -116,14 +116,10 @@ public function setUp(): void { $this->appContainer->expects($this->exactly(2)) ->method('get') - ->withConsecutive( - [FileService::class], - [FilesAppService::class] - ) - ->willReturnOnConsecutiveCalls( - $this->attachmentServiceImpl, - $this->filesAppServiceImpl - ); + ->willReturnMap([ + [FileService::class, $this->attachmentServiceImpl], + [FilesAppService::class, $this->filesAppServiceImpl], + ]); $this->application->expects($this->any()) ->method('getContainer') @@ -150,7 +146,7 @@ public function setUp(): void { public function testRegisterAttachmentService() { $application = $this->createMock(Application::class); - $appContainer = $this->createMock(IAppContainer::class); + $appContainer = $this->createMock(ContainerInterface::class); $fileServiceMock = $this->createMock(FileService::class); $fileAppServiceMock = $this->createMock(FilesAppService::class); @@ -179,22 +175,17 @@ public function testRegisterAttachmentService() { public function testRegisterAttachmentServiceNotExisting() { $this->expectException(InvalidAttachmentType::class); $application = $this->createMock(Application::class); - $appContainer = $this->createMock(IAppContainer::class); + $appContainer = $this->createMock(ContainerInterface::class); $fileServiceMock = $this->createMock(FileService::class); $fileAppServiceMock = $this->createMock(FilesAppService::class); $appContainer->expects($this->exactly(3)) ->method('get') - ->withConsecutive( - [FileService::class], - [FilesAppService::class], - [MyAttachmentService::class] - ) - ->willReturnOnConsecutiveCalls( - $fileServiceMock, - $fileAppServiceMock, - new MyAttachmentService() - ); + ->willReturnMap([ + [FileService::class, $fileServiceMock], + [FilesAppService::class, $fileAppServiceMock], + [MyAttachmentService::class, new MyAttachmentService()], + ]); $application->expects($this->any()) ->method('getContainer') diff --git a/tests/unit/Service/BatchQueryPerformanceTest.php b/tests/unit/Service/BatchQueryPerformanceTest.php index a15502ff6e..d35656aab3 100644 --- a/tests/unit/Service/BatchQueryPerformanceTest.php +++ b/tests/unit/Service/BatchQueryPerformanceTest.php @@ -39,7 +39,6 @@ use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Validators\AttachmentServiceValidator; use OCA\Deck\Validators\CardServiceValidator; -use OCP\AppFramework\IAppContainer; use OCP\Collaboration\Reference\IReferenceManager; use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; @@ -49,6 +48,7 @@ use OCP\IUser; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -321,7 +321,7 @@ private function setUpAttachmentService(): void { // FilesAppService implements ICustomAttachmentService, so mock the full class $this->filesAppServiceImpl = $this->createMock(FilesAppService::class); - $appContainer = $this->createMock(IAppContainer::class); + $appContainer = $this->createMock(ContainerInterface::class); $appContainer->method('get') ->willReturnMap([ [FileService::class, $this->fileServiceImpl],