[TYPO3-dev] Unit tests and localization
Dirk Wenzel
wenzel at webfox03.de
Fri Jul 18 14:58:05 CEST 2014
Hi Helmut,
thank you for your quick reply!
Actually your 'shortcut' was what I did first. But I felt uncomfortable
with it, since it doesn't diminshes the dependencies and leads to more
complicated tests.
I finally opted for adding a translate() method to my base controller
class which I then stubbed in the unit tests.
By the way: I did test for adding concrete strings (from default
language) in addFlashMessage(). Now this seems not such a good idea
anymore. I only test for calling translate() with a certain key and use
a mock return value for addFlashMessage().
Cheers Dirk
Am 17.07.14 20:07, schrieb Helmut Hummel:
>> I tried running my unit tests using a standalone phpunit with
>> bootstrap [1].
>
> Which is good :)
>
>> One of them fails due to a call of
>> \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate() with
>> PHP Fatal error: Call to a member function parse_charset() on a
>> non-object in
>> /var/www/typo3/typo3_src-6.2.3/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php
>>
>> on line 96
>
> With standalone phpunit, $GLOBALS['LANG'] does not exist.
>
>> How could I avoid this?
>>
>> The only solution I see is wrapping those static calls and stub the
>> wrapper method in my tests.
>> What would you do?
>
> It depends what your intention in the test is and what you actually want
> to test. A shortcut would be to mock $GLOBALS['LANG']->csConvObj in your
> test.
>
> I would go with the shortcut in the first run and then maybe refactor
> your (now tested code) to have less dependencies to the framework
> (Extbase LocalizationUtility in that case).
More information about the TYPO3-dev
mailing list