[TYPO3-mvc] Problems with testing Controllers (TDD)

Jochen Rau jochen.rau at typoplanet.de
Sat Jan 2 22:46:15 CET 2010


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 

-- 
I'm trying a new usenet client for Mac, Nemo OS X, since 0 days.
You can download it at http://www.malcom-mac.com/nemo


More information about the TYPO3-project-typo3v4mvc mailing list