mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-26 05:56:13 +01:00

[TASK] Switch the TeaController to construtor injection (#881)

Fixes #869
This commit is contained in:
Oliver Klee 2023-07-03 14:26:21 +02:00 committed by GitHub
parent 97a19b7816
commit b4c93d8dea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View file

@ -16,7 +16,7 @@ class TeaController extends ActionController
{ {
private TeaRepository $teaRepository; private TeaRepository $teaRepository;
public function injectTeaRepository(TeaRepository $teaRepository): void public function __construct(TeaRepository $teaRepository)
{ {
$this->teaRepository = $teaRepository; $this->teaRepository = $teaRepository;
} }

View file

@ -40,19 +40,17 @@ final class TeaControllerTest extends UnitTestCase
{ {
parent::setUp(); parent::setUp();
$this->teaRepositoryMock = $this->getMockBuilder(TeaRepository::class)->disableOriginalConstructor()->getMock();
// 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`.
$methodsToMock = ['htmlResponse', 'redirect', 'redirectToUri']; $methodsToMock = ['htmlResponse', 'redirect', 'redirectToUri'];
if ((new Typo3Version())->getMajorVersion() <= 11) { if ((new Typo3Version())->getMajorVersion() <= 11) {
$methodsToMock[] = 'forward'; $methodsToMock[] = 'forward';
} }
$this->subject = $this->getAccessibleMock(TeaController::class, $methodsToMock); $this->subject = $this->getAccessibleMock(TeaController::class, $methodsToMock, [$this->teaRepositoryMock]);
$this->viewMock = $this->createMock(TemplateView::class); $this->viewMock = $this->createMock(TemplateView::class);
$this->subject->_set('view', $this->viewMock); $this->subject->_set('view', $this->viewMock);
$this->teaRepositoryMock = $this->getMockBuilder(TeaRepository::class)->disableOriginalConstructor()->getMock();
$this->subject->injectTeaRepository($this->teaRepositoryMock);
$responseMock = $this->createMock(HtmlResponse::class); $responseMock = $this->createMock(HtmlResponse::class);
$this->subject->method('htmlResponse')->willReturn($responseMock); $this->subject->method('htmlResponse')->willReturn($responseMock);
} }