From 911208040ed79346993b947cc506af15f78a8b8f Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 9 Sep 2026 20:05:02 -0400 Subject: [PATCH 1/2] refactor(updatenotification): remove unused notifier mock branch The test helper is only called without method overrides, so remove the unused partial-mock path and simplify its signature and return type. Signed-off-by: Josh --- .../tests/Notification/NotifierTest.php | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index 03b2af1f3ef64..b1724d4d71b14 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -51,34 +51,17 @@ protected function setUp(): void { /** * @param array $methods */ - protected function getNotifier(array $methods = []): Notifier|MockObject { - if (empty($methods)) { - return new Notifier( - $this->urlGenerator, - $this->appConfig, - $this->notificationManager, - $this->l10nFactory, - $this->userSession, - $this->groupManager, - $this->appManager, - $this->serverVersion, - ); - } - { - return $this->getMockBuilder(Notifier::class) - ->setConstructorArgs([ - $this->urlGenerator, - $this->appConfig, - $this->notificationManager, - $this->l10nFactory, - $this->userSession, - $this->groupManager, - $this->appManager, - $this->serverVersion, - ]) - ->onlyMethods($methods) - ->getMock(); - } + protected function getNotifier(): Notifier { + return new Notifier( + $this->urlGenerator, + $this->appConfig, + $this->notificationManager, + $this->l10nFactory, + $this->userSession, + $this->groupManager, + $this->appManager, + $this->serverVersion, + ); } public static function dataUpdateAlreadyInstalledCheck(): array { From 63645a55790bc6368edf5989d1dd02a6ab504d8f Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 9 Sep 2026 20:57:42 -0400 Subject: [PATCH 2/2] test(updatenotification): use PHPUnit exception expectations Replace manual try/catch assertions with PHPUnit's expectException() API and split successful and exceptional cases into focused tests. Assisted-by: Copilot:gpt-5.6-luna Signed-off-by: Josh --- .../tests/Notification/NotifierTest.php | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index b1724d4d71b14..98e47b32b59e7 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -64,29 +64,36 @@ protected function getNotifier(): Notifier { ); } - public static function dataUpdateAlreadyInstalledCheck(): array { - return [ - ['1.1.0', '1.0.0', false], - ['1.1.0', '1.1.0', true], - ['1.1.0', '1.2.0', true], - ]; + public function testUpdateAlreadyInstalledCheckWithOlderInstalledVersion(): void { + $notifier = $this->getNotifier(); + + $notification = $this->createMock(INotification::class); + $notification->expects($this->once()) + ->method('getObjectId') + ->willReturn('1.1.0'); + + self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, '1.0.0']); + $this->addToAssertionCount(1); } - #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataUpdateAlreadyInstalledCheck')] - public function testUpdateAlreadyInstalledCheck(string $versionNotification, string $versionInstalled, bool $exception): void { + #[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataAlreadyInstalledVersions')] + public function testUpdateAlreadyInstalledCheckThrows(string $versionInstalled): void { $notifier = $this->getNotifier(); $notification = $this->createMock(INotification::class); $notification->expects($this->once()) ->method('getObjectId') - ->willReturn($versionNotification); - - try { - self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]); - $this->assertFalse($exception); - } catch (\Exception $e) { - $this->assertTrue($exception); - $this->assertInstanceOf(AlreadyProcessedException::class, $e); - } + ->willReturn('1.1.0'); + + $this->expectException(AlreadyProcessedException::class); + + self::invokePrivate($notifier, 'updateAlreadyInstalledCheck', [$notification, $versionInstalled]); + } + + public static function dataAlreadyInstalledVersions(): array { + return [ + ['1.1.0'], + ['1.2.0'], + ]; } }