lundi 26 janvier 2015

Symfony2 - Locale in unit tests

I'm from Germany and at work we use an old Symfony2 Version (2.1). I wrote a twig filter named "GermanDateExtension".



public function getGermanDateFilter($date, $format)
{
setlocale(LC_TIME, 'de_DE.utf8');
return strftime($format, $date);
}


Locale is set via setlocale() and the formatted date will be returned. I also wrote some unit tests for this filter.



public function testGermanDay()
{
$germanDate = new GermanDateExtension();
$result = $germanDate->getGermanDateFilter($this->testDate, '%A');

$this->assertEquals('Mittwoch', $result);
}


The default locale should be "de" (in parameters.ini). The code is working without problems on my website, but the tests fail.


Now here's the problem: If I execute the test, the default locale is "en" and the setlocale() call is ignored. So instead of "Mittwoch" the english name "Wednesday" is returned.


Do you have any ideas how to fix this?


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire