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->teaRepositoryMock]); $this->viewMock = $this->createMock(TemplateView::class); $this->subject->_set('view', $this->viewMock); $responseMock = $this->createMock(HtmlResponse::class); $this->subject->method('htmlResponse')->willReturn($responseMock); } /** * @test */ public function isActionController(): void { self::assertInstanceOf(ActionController::class, $this->subject); } /** * @test */ public function indexActionAssignsAllTeaAsTeasToView(): void { $teas = $this->createMock(QueryResultInterface::class); $this->teaRepositoryMock->method('findAll')->willReturn($teas); $this->viewMock->expects(self::once())->method('assign')->with('teas', $teas); $this->subject->indexAction(); } /** * @test */ public function indexActionReturnsHtmlResponse(): void { $result = $this->subject->indexAction(); self::assertInstanceOf(HtmlResponse::class, $result); } /** * @test */ public function showActionAssignsPassedTeaAsTeaToView(): void { $tea = new Tea(); $this->viewMock->expects(self::once())->method('assign')->with('tea', $tea); $this->subject->showAction($tea); } /** * @test */ public function showActionAssignsReturnsHtmlResponse(): void { $result = $this->subject->showAction(new Tea()); self::assertInstanceOf(HtmlResponse::class, $result); } }