From 882cad7d37589136774d1d880e648e8233a57a78 Mon Sep 17 00:00:00 2001 From: mjansen Date: Tue, 20 Jan 2026 08:55:11 +0100 Subject: [PATCH 1/2] UICore: Suggest that `ilCtrlInteface` will `never` return in "redirect*" methods --- components/ILIAS/UICore/classes/class.ilCtrl.php | 6 +++--- .../ILIAS/UICore/interfaces/interface.ilCtrlInterface.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/ILIAS/UICore/classes/class.ilCtrl.php b/components/ILIAS/UICore/classes/class.ilCtrl.php index 4be9c3e3e97c..def39c475d79 100755 --- a/components/ILIAS/UICore/classes/class.ilCtrl.php +++ b/components/ILIAS/UICore/classes/class.ilCtrl.php @@ -395,7 +395,7 @@ public function redirect( ?string $a_cmd = null, ?string $a_anchor = null, bool $is_async = false - ): void { + ): never { $this->redirectByClass( $this->getClassByObject($a_gui_obj), $a_cmd, @@ -412,7 +412,7 @@ public function redirectByClass( ?string $a_cmd = null, ?string $a_anchor = null, bool $is_async = false - ): void { + ): never { $this->redirectToURL( $this->getLinkTargetByClass( $a_class, @@ -426,7 +426,7 @@ public function redirectByClass( /** * @inheritDoc */ - public function redirectToURL(string $target_url): void + public function redirectToURL(string $target_url): never { // prepend the ILIAS HTTP path if it wasn't already. if (defined("ILIAS_HTTP_PATH") && diff --git a/components/ILIAS/UICore/interfaces/interface.ilCtrlInterface.php b/components/ILIAS/UICore/interfaces/interface.ilCtrlInterface.php index 10587813c80c..28f348d66628 100755 --- a/components/ILIAS/UICore/interfaces/interface.ilCtrlInterface.php +++ b/components/ILIAS/UICore/interfaces/interface.ilCtrlInterface.php @@ -305,7 +305,7 @@ public function redirect( ?string $a_cmd = null, ?string $a_anchor = null, bool $is_async = false - ): void; + ): never; /** * Redirects to the provided GUI class. @@ -321,14 +321,14 @@ public function redirectByClass( ?string $a_cmd = null, ?string $a_anchor = null, bool $is_async = false - ): void; + ): never; /** * Redirects to the given target URL. * * @param string $target_url */ - public function redirectToURL(string $target_url): void; + public function redirectToURL(string $target_url): never; /** * Sets the current object (id and type) of ilCtrl's context. From 639597be423e57d1653cf01f9c819eb2b8cf4f29 Mon Sep 17 00:00:00 2001 From: mjansen Date: Tue, 20 Jan 2026 10:58:51 +0100 Subject: [PATCH 2/2] UICore/AllComponents: Fix tests depending on `ilCtrlInterface::redirect*` This commit fixes tests that implicitly call `ilCtrlInterface` methods that `never` return. --- .../LegalDocuments/tests/ConsumerToolbox/RoutingTest.php | 2 ++ .../tests/Provide/ProvideWithdrawalTest.php | 9 +++------ .../ILIAS/LegalDocuments/tests/StartUpStepTest.php | 2 ++ components/ILIAS/Mail/tests/gui/ilMailOptionsGUITest.php | 3 +++ components/ILIAS/Test/tests/ilObjTestGUITest.php | 8 ++++++-- ...AssQuestionFeedbackPageObjectCommandForwarderTest.php | 2 ++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php index 7345c79ac29b..e4bcffaa1efc 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php @@ -97,6 +97,8 @@ public function testRedirectToOriginalTarget(): void $ctrl = $this->mock(ilCtrl::class); $ctrl->expects(self::once())->method('redirectToURL')->with('some url'); + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + (new Routing( $ctrl, $session, diff --git a/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php b/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php index c8ec532f4bd7..f94d0add9b4a 100755 --- a/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php +++ b/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php @@ -59,8 +59,6 @@ function (array $params): string { public function testFinishAndLogout(): void { - $called = false; - $auth_session = $this->mock(ilAuthSession::class); $auth_session->expects(self::once())->method('logout'); @@ -72,14 +70,13 @@ public function testFinishAndLogout(): void $ctrl, $auth_session, $this->fail(...), - function (int $x) use (&$called) { + function (int $x) { $this->assertSame(ilSession::SESSION_CLOSE_USER, $x); - $called = true; } ); - $instance->finishAndLogout(['bar' => 'baz']); + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); - $this->assertTrue($called); + $instance->finishAndLogout(['bar' => 'baz']); } } diff --git a/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php b/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php index 7a7f2738b4d4..5244d28514a6 100755 --- a/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php +++ b/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php @@ -65,6 +65,8 @@ public function testExecute(): void $this->mockTree(Intercept::class, ['intercept' => true, 'id' => 'baz', 'target' => ['guiName' => 'foo', 'guiPath' => ['foo'], 'command' => 'bar']]), ]])); + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + $instance->execute(); } diff --git a/components/ILIAS/Mail/tests/gui/ilMailOptionsGUITest.php b/components/ILIAS/Mail/tests/gui/ilMailOptionsGUITest.php index 04d2e945f3cf..49713de52bf6 100755 --- a/components/ILIAS/Mail/tests/gui/ilMailOptionsGUITest.php +++ b/components/ILIAS/Mail/tests/gui/ilMailOptionsGUITest.php @@ -122,6 +122,9 @@ public function testMailOptionsAreNotAccessibleIfGlobalAccessIsDeniedAndUserWill $gui = $this->getMailOptionsGUI($http, $ctrl, $options); $gui->setForm($form); + + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + $gui->executeCommand(); } diff --git a/components/ILIAS/Test/tests/ilObjTestGUITest.php b/components/ILIAS/Test/tests/ilObjTestGUITest.php index 5e4155f4ff5d..73d29238b5da 100755 --- a/components/ILIAS/Test/tests/ilObjTestGUITest.php +++ b/components/ILIAS/Test/tests/ilObjTestGUITest.php @@ -85,6 +85,8 @@ public function testRunObject(): void ->method('redirectByClass') ->with([ilRepositoryGUI::class, ilObjTestGUI::class, ilInfoScreenGUI::class]); + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + $testObj->runObject(); } @@ -96,8 +98,10 @@ public function testCancelCreateQuestionObject(): void $ctrl_mock ->expects($this->once()) ->method('redirect') - ->with($testObj, ilObjTestGUI::SHOW_QUESTIONS_CMD) - ; + ->with($testObj, ilObjTestGUI::SHOW_QUESTIONS_CMD); + + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + $testObj->cancelCreateQuestionObject(); } } diff --git a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionFeedbackPageObjectCommandForwarderTest.php b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionFeedbackPageObjectCommandForwarderTest.php index 8891d8e0129d..3b764d3461ed 100644 --- a/components/ILIAS/TestQuestionPool/tests/ilAssQuestionFeedbackPageObjectCommandForwarderTest.php +++ b/components/ILIAS/TestQuestionPool/tests/ilAssQuestionFeedbackPageObjectCommandForwarderTest.php @@ -40,6 +40,8 @@ protected function setUp(): void $tabs = $this->createMock(ilTabsGUI::class); $lng = $this->createMock(ilLanguage::class); + $this->expectException(\PHPUnit\Framework\MockObject\NeverReturningMethodException::class); + $this->object = new ilAssQuestionFeedbackPageObjectCommandForwarder($questionOBJ, $ctrl, $tabs, $lng); }