mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-23 09:16:12 +01:00
tea/Tests/Unit/Controller/TeaControllerTest.php
Oliver Klee 4f2c813d7f
[TASK] Switch to the core testing framework (#361)
The TYPO3 core testing framework has more person-power for maintenance
behind it compared to the nimut testing framework. So we should use that.
2022-02-20 15:18:46 +01:00

84 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace TTN\Tea\Tests\Unit\Controller;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophecy\ProphecySubjectInterface;
use TTN\Tea\Controller\TeaController;
use TTN\Tea\Domain\Model\Product\Tea;
use TTN\Tea\Domain\Repository\Product\TeaRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* @covers \TTN\Tea\Controller\TeaController
*/
class TeaControllerTest extends UnitTestCase
{
/**
* @var TeaController
*/
private $subject;
/**
* @var ObjectProphecy
*/
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, ['redirect', 'forward']);
$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);
}
/**
* @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->subject->indexAction();
}
/**
* @test
*/
public function showActionAssignsPassedTeaAsTeaToView(): void
{
$tea = new Tea();
$this->viewProphecy->assign('tea', $tea)->shouldBeCalled();
$this->subject->showAction($tea);
}
}