diff --git a/CHANGELOG.md b/CHANGELOG.md index c26fa11..a021838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added ### Changed +- Return `ResponseInterface` in controller actions (#597) - Replace switchable controller actions with separate plugins (#575) ### Deprecated diff --git a/Classes/Controller/TeaController.php b/Classes/Controller/TeaController.php index a4674f5..481e4e4 100644 --- a/Classes/Controller/TeaController.php +++ b/Classes/Controller/TeaController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace TTN\Tea\Controller; +use Psr\Http\Message\ResponseInterface; use TTN\Tea\Domain\Model\Product\Tea; use TTN\Tea\Domain\Repository\Product\TeaRepository; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -23,13 +24,15 @@ class TeaController extends ActionController $this->teaRepository = $teaRepository; } - public function indexAction(): void + public function indexAction(): ResponseInterface { $this->view->assign('teas', $this->teaRepository->findAll()); + return $this->htmlResponse(); } - public function showAction(Tea $tea): void + public function showAction(Tea $tea): ResponseInterface { $this->view->assign('tea', $tea); + return $this->htmlResponse(); } } diff --git a/Tests/Unit/Controller/TeaControllerTest.php b/Tests/Unit/Controller/TeaControllerTest.php index 4f4a497..5086bb0 100644 --- a/Tests/Unit/Controller/TeaControllerTest.php +++ b/Tests/Unit/Controller/TeaControllerTest.php @@ -10,6 +10,7 @@ use Prophecy\Prophecy\ProphecySubjectInterface; use TTN\Tea\Controller\TeaController; use TTN\Tea\Domain\Model\Product\Tea; use TTN\Tea\Domain\Repository\Product\TeaRepository; +use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Fluid\View\TemplateView; @@ -41,7 +42,10 @@ class TeaControllerTest extends UnitTestCase parent::setUp(); // We need to create an accessible mock in order to be able to set the protected `view`. - $this->subject = $this->getAccessibleMock(TeaController::class, ['forward', 'redirect', 'redirectToUri']); + $this->subject = $this->getAccessibleMock( + TeaController::class, + ['forward', 'redirect', 'redirectToUri', 'htmlResponse'] + ); $this->viewProphecy = $this->prophesize(TemplateView::class); $view = $this->viewProphecy->reveal(); @@ -51,6 +55,9 @@ class TeaControllerTest extends UnitTestCase /** @var TeaRepository&ProphecySubjectInterface $teaRepository */ $teaRepository = $this->teaRepositoryProphecy->reveal(); $this->subject->injectTeaRepository($teaRepository); + + $response = $this->prophesize(HtmlResponse::class)->reveal(); + $this->subject->method('htmlResponse')->willReturn($response); } /** @@ -69,8 +76,12 @@ class TeaControllerTest extends UnitTestCase $teas = $this->prophesize(QueryResultInterface::class)->reveal(); $this->teaRepositoryProphecy->findAll()->willReturn($teas); $this->viewProphecy->assign('teas', $teas)->shouldBeCalled(); + $this->viewProphecy->render()->willReturn(''); - $this->subject->indexAction(); + self::assertInstanceOf( + HtmlResponse::class, + $this->subject->indexAction() + ); } /** @@ -80,7 +91,11 @@ class TeaControllerTest extends UnitTestCase { $tea = new Tea(); $this->viewProphecy->assign('tea', $tea)->shouldBeCalled(); + $this->viewProphecy->render()->willReturn(''); - $this->subject->showAction($tea); + self::assertInstanceOf( + HtmlResponse::class, + $this->subject->showAction($tea) + ); } }