TASK: Add test with repository
This commit is contained in:
parent
fdcdbd420b
commit
47602a5e0b
3 changed files with 69 additions and 4 deletions
|
@ -21,6 +21,7 @@ namespace Codappix\TestingTalk\Controller;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
|
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
|
||||||
|
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +29,16 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
*/
|
*/
|
||||||
class FrontendUserController extends ActionController
|
class FrontendUserController extends ActionController
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var FrontendUserRepository
|
||||||
|
*/
|
||||||
|
protected $frontendUserRepository;
|
||||||
|
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
$this->view->assign('frontendUsers', $this->frontendUserRepository->findAll());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FrontendUser $frontendUser
|
* @param FrontendUser $frontendUser
|
||||||
*/
|
*/
|
||||||
|
|
27
Classes/Domain/Repository/FrontendUserRepository.php
Normal file
27
Classes/Domain/Repository/FrontendUserRepository.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
namespace Codappix\Domain\Repository;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||||
|
|
||||||
|
class FrontendUserRepository extends Repository
|
||||||
|
{
|
||||||
|
}
|
|
@ -21,8 +21,10 @@ namespace Codappix\TestingTalkTests\Unit\Controller;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Codappix\TestingTalk\Controller\FrontendUserController;
|
use Codappix\TestingTalk\Controller\FrontendUserController;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
|
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
|
||||||
|
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
|
||||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
||||||
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
|
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
|
||||||
|
|
||||||
|
@ -33,24 +35,49 @@ class FrontendUserControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
protected $subject;
|
protected $subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MockObject
|
||||||
|
*/
|
||||||
|
protected $viewMock;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->subject = new FrontendUserController();
|
$this->subject = new FrontendUserController();
|
||||||
|
$this->viewMock = $this->getMockBuilder(ViewInterface::class)->getMock();
|
||||||
|
ObjectAccess::setProperty($this->subject, 'view', $this->viewMock, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function providedFrontendUserIsAssignedToView()
|
public function providedFrontendUserIsAssignedToViewInShowAction()
|
||||||
{
|
{
|
||||||
$frontendUserMock = $this->getMockBuilder(FrontendUser::class)->getMock();
|
$frontendUserMock = $this->getMockBuilder(FrontendUser::class)->getMock();
|
||||||
$viewMock = $this->getMockBuilder(ViewInterface::class)->getMock();
|
|
||||||
ObjectAccess::setProperty($this->subject, 'view', $viewMock, true);
|
|
||||||
|
|
||||||
$viewMock->expects($this->once())
|
$this->viewMock->expects($this->once())
|
||||||
->method('assign')
|
->method('assign')
|
||||||
->with('frontendUser', $frontendUserMock);
|
->with('frontendUser', $frontendUserMock);
|
||||||
|
|
||||||
$this->subject->showAction($frontendUserMock);
|
$this->subject->showAction($frontendUserMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function fetchedFrontendUsersAreAssignedToViewInIndexAction()
|
||||||
|
{
|
||||||
|
$frontendUserRepositoryMock = $this->getMockBuilder(FrontendUserRepository::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
ObjectAccess::setProperty($this->subject, 'frontendUserRepository', $frontendUserRepositoryMock, true);
|
||||||
|
$frontendUserRepositoryMock->expects($this->any())
|
||||||
|
->method('findAll')
|
||||||
|
->willReturn(['user1' => 'test']);
|
||||||
|
|
||||||
|
$this->viewMock->expects($this->once())
|
||||||
|
->method('assign')
|
||||||
|
->with('frontendUsers', ['user1' => 'test']);
|
||||||
|
|
||||||
|
$this->subject->indexAction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue