TASK: Add test with repository

This commit is contained in:
Daniel Siepmann 2018-06-23 20:27:12 +02:00
parent fdcdbd420b
commit 47602a5e0b
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 69 additions and 4 deletions

View file

@ -21,6 +21,7 @@ namespace Codappix\TestingTalk\Controller;
*/
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
@ -28,6 +29,16 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
*/
class FrontendUserController extends ActionController
{
/**
* @var FrontendUserRepository
*/
protected $frontendUserRepository;
public function indexAction()
{
$this->view->assign('frontendUsers', $this->frontendUserRepository->findAll());
}
/**
* @param FrontendUser $frontendUser
*/

View 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
{
}

View file

@ -21,8 +21,10 @@ namespace Codappix\TestingTalkTests\Unit\Controller;
*/
use Codappix\TestingTalk\Controller\FrontendUserController;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
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\Reflection\ObjectAccess;
@ -33,24 +35,49 @@ class FrontendUserControllerTest extends TestCase
*/
protected $subject;
/**
* @var MockObject
*/
protected $viewMock;
public function setUp()
{
$this->subject = new FrontendUserController();
$this->viewMock = $this->getMockBuilder(ViewInterface::class)->getMock();
ObjectAccess::setProperty($this->subject, 'view', $this->viewMock, true);
}
/**
* @test
*/
public function providedFrontendUserIsAssignedToView()
public function providedFrontendUserIsAssignedToViewInShowAction()
{
$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')
->with('frontendUser', $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();
}
}