Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app-framework): Add native argument types for middleware #36343

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/public/AppFramework/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
namespace OCP\AppFramework;

use Exception;
use OCP\AppFramework\Http\Response;

/**
Expand All @@ -45,7 +46,7 @@ abstract class Middleware {
* @return void
* @since 6.0.0
*/
public function beforeController($controller, $methodName) {
public function beforeController(Controller $controller, string $methodName) {
}


Expand All @@ -59,12 +60,12 @@ public function beforeController($controller, $methodName) {
* @param Controller $controller the controller that is being called
* @param string $methodName the name of the method that will be called on
* the controller
* @param \Exception $exception the thrown exception
* @throws \Exception the passed in exception if it can't handle it
* @param Exception $exception the thrown exception
* @throws Exception the passed in exception if it can't handle it
* @return Response a Response object in case that the exception was handled
* @since 6.0.0
*/
public function afterException($controller, $methodName, \Exception $exception) {
public function afterException(Controller $controller, string $methodName, Exception $exception) {
throw $exception;
}

Expand All @@ -80,7 +81,7 @@ public function afterException($controller, $methodName, \Exception $exception)
* @return Response a Response object
* @since 6.0.0
*/
public function afterController($controller, $methodName, Response $response) {
public function afterController(Controller $controller, string $methodName, Response $response) {
return $response;
}

Expand All @@ -96,7 +97,7 @@ public function afterController($controller, $methodName, Response $response) {
* @return string the output that should be printed
* @since 6.0.0
*/
public function beforeOutput($controller, $methodName, $output) {
public function beforeOutput(Controller $controller, string $methodName, string $output) {
return $output;
}
}
16 changes: 8 additions & 8 deletions tests/lib/AppFramework/Middleware/MiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ protected function setUp(): void {
}


public function testBeforeController() {
$this->middleware->beforeController($this->controller, null);
public function testBeforeController(): void {
$this->middleware->beforeController($this->controller, '');
$this->assertNull(null);
}


public function testAfterExceptionRaiseAgainWhenUnhandled() {
public function testAfterExceptionRaiseAgainWhenUnhandled(): void {
$this->expectException(\Exception::class);
$this->middleware->afterException($this->controller, null, $this->exception);
$this->middleware->afterException($this->controller, '', $this->exception);
}


public function testAfterControllerReturnResponseWhenUnhandled() {
$response = $this->middleware->afterController($this->controller, null, $this->response);
public function testAfterControllerReturnResponseWhenUnhandled(): void {
$response = $this->middleware->afterController($this->controller, '', $this->response);

$this->assertEquals($this->response, $response);
}


public function testBeforeOutputReturnOutputhenUnhandled() {
$output = $this->middleware->beforeOutput($this->controller, null, 'test');
public function testBeforeOutputReturnOutputhenUnhandled(): void {
$output = $this->middleware->beforeOutput($this->controller, '', 'test');

$this->assertEquals('test', $output);
}
Expand Down