Skip to content

Commit

Permalink
Fixed tests with different user locale settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Renaud Bredy committed Oct 14, 2016
1 parent 99bd38c commit 8776926
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/Jasny/Twig/DateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function getFormat($format, $calendar=\IntlDateFormatter::GREGORIAN)
*/
protected function getDefaultDatePattern($calendar=\IntlDateFormatter::GREGORIAN)
{
return preg_replace('/\byy?\b/', 'yyyy', \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, null, $calendar)->getPattern());
return preg_replace('/\byy?\b/', 'yyyy', \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, \IntlTimeZone::getGMT(), $calendar)->getPattern());
}

/**
Expand All @@ -97,7 +97,7 @@ public function localDate($date, $format=null, $calendar='gregorian')
$calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN;
list($format, $pattern) = $this->getFormat($format, $calendar);

$df = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, null, $calendar, $pattern);
$df = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, \IntlTimeZone::getGMT(), $calendar, $pattern);
return $df->format($date->getTimestamp());
}

Expand All @@ -120,7 +120,7 @@ public function localTime($date, $format='short', $calendar='gregorian')
$calendar = $calendar == 'traditional' ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN;
list($format, $pattern) = $this->getFormat($format, $calendar);

$df = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, $format, null, $calendar, $pattern);
$df = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, $format, \IntlTimeZone::getGMT(), $calendar, $pattern);
return $df->format($date->getTimestamp());
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public function localDateTime($date, $format=null, $calendar='gregorian')

list($format, $pattern) = $this->getFormat($format, $calendar);

$df = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::SHORT, null, $calendar, $pattern);
$df = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::SHORT, \IntlTimeZone::getGMT(), $calendar, $pattern);
return $df->format($date->getTimestamp());
}

Expand Down
7 changes: 3 additions & 4 deletions tests/Jasny/Twig/ArrayExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Jasny\Twig;

use Jasny\Twig\ArrayExtension;

class ArrayExtensionTest extends PHPUnit_Framework_TestCase {
class ArrayExtensionTest extends \PHPUnit_Framework_TestCase {

private function buildEnv($template) {
$loader = new Twig_Loader_Array(array(
$loader = new \Twig_Loader_Array(array(
'template' => $template,
));
$twig = new Twig_Environment($loader);
$twig = new \Twig_Environment($loader);
$twig->addExtension(new ArrayExtension());
return $twig;
}
Expand Down
11 changes: 5 additions & 6 deletions tests/Jasny/Twig/DateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

namespace Jasny\Twig;

use Jasny\Twig\DateExtension;

class DateExtensionTest extends PHPUnit_Framework_TestCase {
class DateExtensionTest extends \PHPUnit_Framework_TestCase {

public static function setUpBeforeClass() {
parent::setUpBeforeClass();
Locale::setDefault("en_CA");
\Locale::setDefault("en_EN");
}

private function buildEnv($template) {
$loader = new Twig_Loader_Array(array(
$loader = new \Twig_Loader_Array(array(
'template' => $template,
));
$twig = new Twig_Environment($loader);
$twig = new \Twig_Environment($loader);
$twig->addExtension(new DateExtension());
return $twig;
}
Expand Down Expand Up @@ -48,7 +47,7 @@ public function testLocalTime() {
}

public function testLocalTimeLong() {
$this->check('11:14:12 PM PDT', "{{ '23:14:12'|localtime('long') }}");
$this->check('11:14:12 PM GMT', "{{ '23:14:12'|localtime('long') }}");
}

public function testLocalTimeShort() {
Expand Down
9 changes: 4 additions & 5 deletions tests/Jasny/Twig/PcreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Jasny\Twig;

use Jasny\Twig\PcreExtension;

class PcreExtensionTest extends PHPUnit_Framework_TestCase {
class PcreExtensionTest extends \PHPUnit_Framework_TestCase {

private function buildEnv($template) {
$loader = new Twig_Loader_Array(array(
$loader = new \Twig_Loader_Array(array(
'template' => $template,
));
$twig = new Twig_Environment($loader);
$twig = new \Twig_Environment($loader);
$twig->addExtension(new PcreExtension());
return $twig;
}
Expand Down Expand Up @@ -43,7 +42,7 @@ public function testPregMatchNo() {
}

/**
* @expectedException Twig_Error_Runtime
* @expectedException \Twig_Error_Runtime
*/
public function testPregMatchError() {
$this->check('NO', '{% if "fod"|preg_match("/o//o/") %}YES{% else %}NO{% endif %}');
Expand Down
7 changes: 3 additions & 4 deletions tests/Jasny/Twig/TextExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Jasny\Twig;

use Jasny\Twig\TextExtension;

class TextExtensionTest extends PHPUnit_Framework_TestCase {
class TextExtensionTest extends \PHPUnit_Framework_TestCase {

private function buildEnv($template) {
$loader = new Twig_Loader_Array(array(
$loader = new \Twig_Loader_Array(array(
'template' => $template,
));
$twig = new Twig_Environment($loader);
$twig = new \Twig_Environment($loader);
$twig->addExtension(new TextExtension());
return $twig;
}
Expand Down

0 comments on commit 8776926

Please sign in to comment.