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

Sebastian Kurfürst sebastian at typo3.org
Sat Jan 2 10:02:05 CET 2010


Hi Michael,

you are currently using a so-called "Stub Object" (see
http://martinfowler.com/articles/mocksArentStubs.html ), i.e. a
"placeholder object" which extends the original object for testing.

I'd suggest that you use _mocks_ instead, as they have assertions as well.

There is a very helpful way to be able to test protected methods:

Initialize a class like this:
$myController =
$this->getMock($this->buildAccessibleProxy('Tx_...Controller'),
array('dummy));

Because of the "buildAccessibleProxy" wrapper, your class now has a few
extra methods (see the BaseTestCase in Extbase for the code):
_get and _set to set and get protected properties
_call to call a protected method

So, then you can definitely get rid of the extra code. Additionally, you
can use more complex assertions on the mock objects:

http://www.phpunit.de/manual/3.0/en/mock-objects.html

Hope this helps :)
Greets,
Sebastian


More information about the TYPO3-project-typo3v4mvc mailing list