mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2024-11-10 03:56:12 +01:00
[TASK] Return ResponseInterface
in controller actions (#597)
Co-authored-by: lina.wolf <lwolf@w-commerce.de>
This commit is contained in:
parent
aa9b52155c
commit
5d3fcee00e
3 changed files with 24 additions and 5 deletions
|
@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- Return `ResponseInterface` in controller actions (#597)
|
||||||
- Replace switchable controller actions with separate plugins (#575)
|
- Replace switchable controller actions with separate plugins (#575)
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace TTN\Tea\Controller;
|
namespace TTN\Tea\Controller;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use TTN\Tea\Domain\Model\Product\Tea;
|
use TTN\Tea\Domain\Model\Product\Tea;
|
||||||
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
@ -23,13 +24,15 @@ class TeaController extends ActionController
|
||||||
$this->teaRepository = $teaRepository;
|
$this->teaRepository = $teaRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction(): void
|
public function indexAction(): ResponseInterface
|
||||||
{
|
{
|
||||||
$this->view->assign('teas', $this->teaRepository->findAll());
|
$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);
|
$this->view->assign('tea', $tea);
|
||||||
|
return $this->htmlResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Prophecy\Prophecy\ProphecySubjectInterface;
|
||||||
use TTN\Tea\Controller\TeaController;
|
use TTN\Tea\Controller\TeaController;
|
||||||
use TTN\Tea\Domain\Model\Product\Tea;
|
use TTN\Tea\Domain\Model\Product\Tea;
|
||||||
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
||||||
|
use TYPO3\CMS\Core\Http\HtmlResponse;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
||||||
use TYPO3\CMS\Fluid\View\TemplateView;
|
use TYPO3\CMS\Fluid\View\TemplateView;
|
||||||
|
@ -41,7 +42,10 @@ class TeaControllerTest extends UnitTestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// We need to create an accessible mock in order to be able to set the protected `view`.
|
// 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);
|
$this->viewProphecy = $this->prophesize(TemplateView::class);
|
||||||
$view = $this->viewProphecy->reveal();
|
$view = $this->viewProphecy->reveal();
|
||||||
|
@ -51,6 +55,9 @@ class TeaControllerTest extends UnitTestCase
|
||||||
/** @var TeaRepository&ProphecySubjectInterface $teaRepository */
|
/** @var TeaRepository&ProphecySubjectInterface $teaRepository */
|
||||||
$teaRepository = $this->teaRepositoryProphecy->reveal();
|
$teaRepository = $this->teaRepositoryProphecy->reveal();
|
||||||
$this->subject->injectTeaRepository($teaRepository);
|
$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();
|
$teas = $this->prophesize(QueryResultInterface::class)->reveal();
|
||||||
$this->teaRepositoryProphecy->findAll()->willReturn($teas);
|
$this->teaRepositoryProphecy->findAll()->willReturn($teas);
|
||||||
$this->viewProphecy->assign('teas', $teas)->shouldBeCalled();
|
$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();
|
$tea = new Tea();
|
||||||
$this->viewProphecy->assign('tea', $tea)->shouldBeCalled();
|
$this->viewProphecy->assign('tea', $tea)->shouldBeCalled();
|
||||||
|
$this->viewProphecy->render()->willReturn('');
|
||||||
|
|
||||||
$this->subject->showAction($tea);
|
self::assertInstanceOf(
|
||||||
|
HtmlResponse::class,
|
||||||
|
$this->subject->showAction($tea)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue