TASK: Add tests
This commit is contained in:
parent
ad85bb0444
commit
fdcdbd420b
4 changed files with 126 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,4 +2,4 @@ composer.lock
|
|||
vendor
|
||||
index.php
|
||||
typo3
|
||||
Tests
|
||||
/Tests
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
namespace Codappix\TestingTalkTests\Unit\Controller;
|
||||
|
||||
/*
|
||||
* 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 Codappix\TestingTalk\Controller\FrontendUserController;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
|
||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
||||
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
|
||||
|
||||
class FrontendUserControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var FrontendUserController
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->subject = new FrontendUserController();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function providedFrontendUserIsAssignedToView()
|
||||
{
|
||||
$frontendUserMock = $this->getMockBuilder(FrontendUser::class)->getMock();
|
||||
$viewMock = $this->getMockBuilder(ViewInterface::class)->getMock();
|
||||
ObjectAccess::setProperty($this->subject, 'view', $viewMock, true);
|
||||
|
||||
$viewMock->expects($this->once())
|
||||
->method('assign')
|
||||
->with('frontendUser', $frontendUserMock);
|
||||
|
||||
$this->subject->showAction($frontendUserMock);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
namespace Codappix\TestingTalk\Tests\Unit\Domain\Model;
|
||||
|
||||
/*
|
||||
* 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 Codappix\TestingTalk\Domain\Model\Address;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AddressTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function streetIsTrimmed()
|
||||
{
|
||||
$subject = new Address(' Street ', '');
|
||||
|
||||
$this->assertSame(
|
||||
'Street',
|
||||
$subject->getStreet(),
|
||||
'Street was not trimmed.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function houseNumberIsTrimmed()
|
||||
{
|
||||
$subject = new Address('', ' 12 a ');
|
||||
|
||||
$this->assertSame(
|
||||
'12 a',
|
||||
$subject->getHouseNumber(),
|
||||
'House number was not trimmed.'
|
||||
);
|
||||
}
|
||||
}
|
15
readme.rst
15
readme.rst
|
@ -34,7 +34,7 @@ Links:
|
|||
Create first test
|
||||
-----------------
|
||||
|
||||
We want to test the controller first::
|
||||
We want to test the model first::
|
||||
|
||||
mkdir -p Tests/Unit/Domain/Model
|
||||
cp Resources/Private/CodeExamples/Tests/Unit/Domain/Model/AddressTest.php \
|
||||
|
@ -43,3 +43,16 @@ We want to test the controller first::
|
|||
Execute first test::
|
||||
|
||||
./vendor/bin/phpunit Tests/Unit/
|
||||
|
||||
Create test for controller
|
||||
--------------------------
|
||||
|
||||
We want to test the controller now::
|
||||
|
||||
mkdir -p Tests/Unit/Controller
|
||||
cp Resources/Private/CodeExamples/Tests/Unit/Controller/FrontendUserControllerTest.php \
|
||||
Tests/Unit/Controller
|
||||
|
||||
Execute all tests::
|
||||
|
||||
./vendor/bin/phpunit Tests/Unit/
|
||||
|
|
Loading…
Reference in a new issue