[TYPO3-dev] Unit tests and localization

Helmut Hummel helmut.hummel at typo3.org
Thu Jul 17 20:07:32 CEST 2014


Hi!

On 16.07.14 12:45, Dirk Wenzel wrote:

> 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).

Kind regards,
Helmut

-- 
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 Core Developer, TYPO3 Security Team Member

TYPO3 .... inspiring people to share!
Get involved: typo3.org



More information about the TYPO3-dev mailing list