diff --git a/Classes/Controller/TeaController.php b/Classes/Controller/TeaController.php index 4ca1682..ed7a1b6 100644 --- a/Classes/Controller/TeaController.php +++ b/Classes/Controller/TeaController.php @@ -16,7 +16,7 @@ class TeaController extends ActionController { private TeaRepository $teaRepository; - public function injectTeaRepository(TeaRepository $teaRepository): void + public function __construct(TeaRepository $teaRepository) { $this->teaRepository = $teaRepository; } diff --git a/Tests/Unit/Controller/TeaControllerTest.php b/Tests/Unit/Controller/TeaControllerTest.php index b6c59d8..8525566 100644 --- a/Tests/Unit/Controller/TeaControllerTest.php +++ b/Tests/Unit/Controller/TeaControllerTest.php @@ -40,19 +40,17 @@ final class TeaControllerTest extends UnitTestCase { 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`. $methodsToMock = ['htmlResponse', 'redirect', 'redirectToUri']; if ((new Typo3Version())->getMajorVersion() <= 11) { $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->subject->_set('view', $this->viewMock); - $this->teaRepositoryMock = $this->getMockBuilder(TeaRepository::class)->disableOriginalConstructor()->getMock(); - $this->subject->injectTeaRepository($this->teaRepositoryMock); - $responseMock = $this->createMock(HtmlResponse::class); $this->subject->method('htmlResponse')->willReturn($responseMock); }