mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-12-22 18:46:11 +01:00

[TASK] Return ResponseInterface in controller actions (#597)

Co-authored-by: lina.wolf <lwolf@w-commerce.de>
This commit is contained in:
Lina Wolf 2022-10-03 16:02:32 +02:00 committed by GitHub
parent aa9b52155c
commit 5d3fcee00e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View file

@ -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

View file

@ -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();
}
}

View file

@ -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)
);
}
}