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;
|
2022-10-09 06:19:32 +02:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
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;
|
2022-10-03 16:02:32 +02:00
|
|
|
use TYPO3\CMS\Core\Http\HtmlResponse;
|
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-10-09 06:19:32 +02:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2018-05-26 20:46:55 +02:00
|
|
|
/**
|
2022-04-20 15:05:45 +02:00
|
|
|
* @var TeaController&MockObject&AccessibleObjectInterface
|
2018-05-26 20:46:55 +02:00
|
|
|
*/
|
2022-10-10 16:05:06 +02:00
|
|
|
private TeaController $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
|
|
|
*/
|
2022-10-06 17:51:41 +02:00
|
|
|
private ObjectProphecy $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
|
|
|
*/
|
2022-10-06 17:51:41 +02:00
|
|
|
private ObjectProphecy $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`.
|
2022-10-03 16:02:32 +02:00
|
|
|
$this->subject = $this->getAccessibleMock(
|
|
|
|
TeaController::class,
|
|
|
|
['forward', 'redirect', 'redirectToUri', 'htmlResponse']
|
|
|
|
);
|
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);
|
2022-10-03 16:02:32 +02:00
|
|
|
|
|
|
|
$response = $this->prophesize(HtmlResponse::class)->reveal();
|
|
|
|
$this->subject->method('htmlResponse')->willReturn($response);
|
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();
|
2022-10-03 16:02:32 +02:00
|
|
|
$this->viewProphecy->render()->willReturn('');
|
2018-05-26 20:46:55 +02:00
|
|
|
|
2022-10-03 16:02:32 +02:00
|
|
|
self::assertInstanceOf(
|
|
|
|
HtmlResponse::class,
|
|
|
|
$this->subject->indexAction()
|
|
|
|
);
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|
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();
|
2022-10-03 16:02:32 +02:00
|
|
|
$this->viewProphecy->render()->willReturn('');
|
2018-05-28 17:05:39 +02:00
|
|
|
|
2022-10-03 16:02:32 +02:00
|
|
|
self::assertInstanceOf(
|
|
|
|
HtmlResponse::class,
|
|
|
|
$this->subject->showAction($tea)
|
|
|
|
);
|
2018-05-28 17:05:39 +02:00
|
|
|
}
|
2018-05-26 20:46:55 +02:00
|
|
|
}
|