*/ private $viewProphecy; /** * @var ObjectProphecy */ private $teaRepositoryProphecy; protected function setUp(): void { 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', 'htmlResponse'] ); $this->viewProphecy = $this->prophesize(TemplateView::class); $view = $this->viewProphecy->reveal(); $this->subject->_set('view', $view); $this->teaRepositoryProphecy = $this->prophesize(TeaRepository::class); /** @var TeaRepository&ProphecySubjectInterface $teaRepository */ $teaRepository = $this->teaRepositoryProphecy->reveal(); $this->subject->injectTeaRepository($teaRepository); $response = $this->prophesize(HtmlResponse::class)->reveal(); $this->subject->method('htmlResponse')->willReturn($response); } /** * @test */ public function isActionController(): void { self::assertInstanceOf(ActionController::class, $this->subject); } /** * @test */ public function indexActionAssignsAllTeaAsTeasToView(): void { $teas = $this->prophesize(QueryResultInterface::class)->reveal(); $this->teaRepositoryProphecy->findAll()->willReturn($teas); $this->viewProphecy->assign('teas', $teas)->shouldBeCalled(); $this->viewProphecy->render()->willReturn(''); self::assertInstanceOf( HtmlResponse::class, $this->subject->indexAction() ); } /** * @test */ public function showActionAssignsPassedTeaAsTeaToView(): void { $tea = new Tea(); $this->viewProphecy->assign('tea', $tea)->shouldBeCalled(); $this->viewProphecy->render()->willReturn(''); self::assertInstanceOf( HtmlResponse::class, $this->subject->showAction($tea) ); } }