2018-05-26 20:46:55 +02:00
|
|
|
<?php
|
2019-12-07 12:13:32 +01:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-12-01 12:16:06 +01:00
|
|
|
namespace TTN\Tea\Tests\Unit\Controller;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2022-04-20 15:05:45 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-12-07 17:44:32 +01:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Prophecy\Prophecy\ProphecySubjectInterface;
|
2019-12-01 12:16:06 +01:00
|
|
|
use TTN\Tea\Controller\TeaController;
|
|
|
|
use TTN\Tea\Domain\Model\Product\Tea;
|
|
|
|
use TTN\Tea\Domain\Repository\Product\TeaRepository;
|
2018-05-26 20:46:55 +02:00
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
|
|
|
use TYPO3\CMS\Fluid\View\TemplateView;
|
2022-04-20 15:05:45 +02:00
|
|
|
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
|
2022-02-20 15:18:46 +01:00
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2021-09-15 02:11:15 +02:00
|
|
|
* @covers \TTN\Tea\Controller\TeaController
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
|
|
|
class TeaControllerTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
/**
|
2022-04-20 15:05:45 +02:00
|
|
|
* @var TeaController&MockObject&AccessibleObjectInterface
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2021-11-17 13:14:43 +01:00
|
|
|
private $subject;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2022-02-28 17:58:06 +01:00
|
|
|
* @var ObjectProphecy<TemplateView>
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2021-11-17 13:14:43 +01:00
|
|
|
private $viewProphecy;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
/**
|
2022-02-28 17:58:06 +01:00
|
|
|
* @var ObjectProphecy<TeaRepository>
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2021-11-17 13:14:43 +01:00
|
|
|
private $teaRepositoryProphecy;
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2019-08-12 17:25:59 +02:00
|
|
|
protected function setUp(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
2022-02-20 15:18:46 +01:00
|
|
|
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']);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
$this->viewProphecy = $this->prophesize(TemplateView::class);
|
2019-08-12 17:43:02 +02:00
|
|
|
$view = $this->viewProphecy->reveal();
|
2022-02-20 15:18:46 +01:00
|
|
|
$this->subject->_set('view', $view);
|
2018-05-26 20:46:55 +02:00
|
|
|
|
|
|
|
$this->teaRepositoryProphecy = $this->prophesize(TeaRepository::class);
|
2021-09-15 02:09:37 +02:00
|
|
|
/** @var TeaRepository&ProphecySubjectInterface $teaRepository */
|
2019-08-12 17:43:02 +02:00
|
|
|
$teaRepository = $this->teaRepositoryProphecy->reveal();
|
|
|
|
$this->subject->injectTeaRepository($teaRepository);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function isActionController(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
2019-08-12 17:25:59 +02:00
|
|
|
self::assertInstanceOf(ActionController::class, $this->subject);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function indexActionAssignsAllTeaAsTeasToView(): void
|
2018-05-26 20:46:55 +02:00
|
|
|
{
|
|
|
|
$teas = $this->prophesize(QueryResultInterface::class)->reveal();
|
|
|
|
$this->teaRepositoryProphecy->findAll()->willReturn($teas);
|
|
|
|
$this->viewProphecy->assign('teas', $teas)->shouldBeCalled();
|
|
|
|
|
|
|
|
$this->subject->indexAction();
|
|
|
|
}
|
2018-05-28 17:05:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2019-08-12 17:25:59 +02:00
|
|
|
public function showActionAssignsPassedTeaAsTeaToView(): void
|
2018-05-28 17:05:39 +02:00
|
|
|
{
|
|
|
|
$tea = new Tea();
|
|
|
|
$this->viewProphecy->assign('tea', $tea)->shouldBeCalled();
|
|
|
|
|
|
|
|
$this->subject->showAction($tea);
|
|
|
|
}
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|