[TYPO3-mvc] Problems with testing Controllers (TDD)
Michael Knoll
mimi at kaktusteam.de
Tue Jan 5 03:41:57 CET 2010
Hi Jochen,
thanks a lot! I thought, I would get a problem when testing controllers
without overwriting the "redirect" action. But after thinking about it
for I while, I can't see the problem, as long as I catch the error
thrown by the controller on redirect...
So I will give it a try tomorrow.
Do you think, it's a good idea to test controller actions anyway? I
thought it would be a nice and easy way, to check, whether the actions
are all still running after refactoring for example...
Hope to see you some day soon in Karlsruhe to talk about all that stuff
- did a lot of ExtBase learning during the past couple of days and I'm
really excited to share my thoughts and ideas with you on that to climb
the next hill in Extbase Extension Development :-)
Greetings
Michael
Jochen Rau schrieb:
> Hi Michael,
>
> here is an example of a test I have written. Hope it helps.
>
> /**
> * Testcase for the OrganizationController class
> */
> class Tx_SjrOffers_Controller_OrganizationControllerTest extends
> Tx_Extbase_BaseTestCase {
>
> /**
> * @test
> */
> public function indexActionWorks() {
> $mockOrganizationRepository = $this->getMock
> ('Tx_SjrOffers_Domain_Repository_OrganizationRepository', array
> ('findAll'), array(), '', FALSE);
> $mockOrganizationRepository->expects($this->once())->method
> ('findAll')->will($this->returnValue(array('organization1',
> 'organization2')));
>
> $mockView = $this->getMock('Tx_Fluid_Core_View_TemplateView',
> array('assign'), array(), '', FALSE);
> $mockView->expects($this->once())->method('assign')->with
> ('organizations', array('organization1', 'organization2'));
>
> $mockController = $this->getMock($this->buildAccessibleProxy
> ('Tx_SjrOffers_Controller_OrganizationController'), array('dummy'),
> array(), '', FALSE);
> $mockController->_set('organizationRepository',
> $mockOrganizationRepository);
> $mockController->_set('view', $mockView);
> $mockController->indexAction();
> }
>
> }
>
> Regards
> Jochen
>
More information about the TYPO3-project-typo3v4mvc
mailing list