[TYPO3-mvc] HowTo write UnitTest for Controller?

Heinz Schilling webdesign at webtekk.ch
Sun Mar 17 13:38:36 CET 2013


I like the concept of Test-Driven Development, but can't understand the writing of a controller test.

I hope I get some help and explanation here from you.

TYPO3 6.0.4
Extbase 6.0.0
Fluid 6.0.0
PHPUnit 3.6.12

Replace <Vendor> with your company name for example.
Replace <Extension> with your extension name.

Classes/Domain/Model/Client.php
<?php
namespace <Vendor>\<Extension>\Domain\Model;
class Client extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
    ...
}
?>

Domain/Repository/ClientRepository.php
<?php
namespace <Vendor>\<Extension>\Domain\Repository;
class ClientRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
}
?>

Classes/Controller/ClientController.php
<?php
namespace <Vendor>\<Extension>\Controller;
class ClientController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

    /**
     * clientRepository
     *
     * @var \<Vendor>\<Extension>\Domain\Repository\ClientRepository
     * @inject
     */
    protected $clientRepository;

    /**
     * action list
     *
     * @return void
     */
    public function listAction() {
        $clients = $this->clientRepository->findAll();
        $this->view->assign('clients', $clients);
    }
    ...
}
?>

Tests/Unit/Controller/ClientControllerTest.php
<?php
namespace <Vendor>\<Extension>\Tests;
class ClientControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
    ???

    /**
     * @test
     */
    public function listActionFindAllClients() {
        ???
    }

}
?>

Examples I found with Google are old or without namespace or haven't any code description. I don't get them all together to a understandable example for me.

Thank you for helping
Heinz


More information about the TYPO3-project-typo3v4mvc mailing list