Skip to content

Commit

Permalink
TASK: Adjust StopActionException::createForResponse to use psr resp…
Browse files Browse the repository at this point in the history
…onse
  • Loading branch information
mhsdesign committed Feb 6, 2024
1 parent 09c24f5 commit 41315e0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Mvc/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function redirectToUri(string|UriInterface $uri, int $delay = 0, int $
$this->response->setStatusCode($statusCode);
$this->response->setContent('<html><head><meta http-equiv="refresh" content="' . (int)$delay . ';url=' . $uri . '"/></head></html>');
}
throw StopActionException::createForResponse($this->response, '');
throw StopActionException::createForResponse($this->response->buildHttpResponse(), '');
}

/**
Expand All @@ -358,7 +358,7 @@ protected function throwStatus(int $statusCode, $statusMessage = null, $content
);
}
$this->response->setContent($content);
throw StopActionException::createForResponse($this->response, $content);
throw StopActionException::createForResponse($this->response->buildHttpResponse(), $content);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Neos.Flow/Classes/Mvc/Controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7\Utils;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
Expand Down Expand Up @@ -134,7 +135,7 @@ protected function redirectToUri(string|UriInterface $uri, int $delay = 0, int $
parent::redirectToUri($uri, $delay, $statusCode);
} catch (StopActionException $exception) {
if ($this->request->getFormat() === 'json') {
$exception->response->setContent('');
throw StopActionException::createForResponse($exception->response->withBody(Utils::streamFor('')), '');
}
throw $exception;
}
Expand Down
7 changes: 3 additions & 4 deletions Neos.Flow/Classes/Mvc/Exception/StopActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ private function __construct(string $message, int $code, ?\Throwable $previous,
}

/**
* @deprecated
* @param ActionResponse $response The response to be received by the MVC Dispatcher.
* @param ResponseInterface $response The response to be received by the MVC Dispatcher.
* @param string $details Additional details just for this exception, in case it is logged (the regular exception message).
*/
public static function createForResponse(ActionResponse $response, string $details): self
public static function createForResponse(ResponseInterface $response, string $details): self
{
if (empty($details)) {
$details = sprintf(
'Stop action with %s response.',
$response->getStatusCode()
);
}
return new self($details, 1558088618, null, $response->buildHttpResponse());
return new self($details, 1558088618, null, $response);
}
}
6 changes: 3 additions & 3 deletions Neos.Flow/Tests/Unit/Mvc/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function dispatchIgnoresStopExceptionsForFirstLevelActionRequests()
$this->mockParentRequest->expects(self::exactly(2))->method('isDispatched')->willReturnOnConsecutiveCalls(false, true);
$this->mockParentRequest->expects(self::once())->method('isMainRequest')->willReturn(true);

$this->mockController->expects(self::atLeastOnce())->method('processRequest')->will(self::throwException(StopActionException::createForResponse(new ActionResponse(), '')));
$this->mockController->expects(self::atLeastOnce())->method('processRequest')->will(self::throwException(StopActionException::createForResponse(new Response(), '')));

$this->dispatcher->dispatch($this->mockParentRequest);
}
Expand All @@ -169,7 +169,7 @@ public function dispatchCatchesStopExceptionOfActionRequestsAndRollsBackToThePar
$this->mockActionRequest->expects(self::atLeastOnce())->method('isDispatched')->willReturn(false);
$this->mockParentRequest->expects(self::atLeastOnce())->method('isDispatched')->willReturn(true);

$this->mockController->expects(self::atLeastOnce())->method('processRequest')->will(self::throwException(StopActionException::createForResponse(new ActionResponse(), '')));
$this->mockController->expects(self::atLeastOnce())->method('processRequest')->will(self::throwException(StopActionException::createForResponse(new Response(), '')));

$this->dispatcher->dispatch($this->mockActionRequest, $this->actionResponse);
}
Expand All @@ -188,7 +188,7 @@ public function dispatchContinuesWithNextRequestFoundInAForwardException()

$this->mockController->expects(self::exactly(2))->method('processRequest')
->withConsecutive([$this->mockActionRequest], [$this->mockParentRequest])
->willReturnOnConsecutiveCalls(self::throwException(StopActionException::createForResponse(new ActionResponse(), '')), self::throwException($forwardException));
->willReturnOnConsecutiveCalls(self::throwException(StopActionException::createForResponse(new Response(), '')), self::throwException($forwardException));

$this->dispatcher->dispatch($this->mockActionRequest);
}
Expand Down

0 comments on commit 41315e0

Please sign in to comment.