Forráskód Böngészése

[Locale] re-order StubIntlDateFormatter methods, rename timezoneId to timeZoneId, add setLenient method

Igor Wiedler 14 éve
szülő
commit
77258223f1

+ 46 - 41
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -60,7 +60,7 @@ class StubIntlDateFormatter
         $this->timetype = $timetype;
 
         $this->setPattern($pattern);
-        $this->setTimezoneId($timezone);
+        $this->setTimeZoneId($timezone);
     }
 
     public function format($timestamp)
@@ -215,50 +215,39 @@ class StubIntlDateFormatter
         return $formatted;
     }
 
-    public function getLocale()
+    public function getCalendar()
     {
-        return 'en';
+        return self::GREGORIAN;
     }
 
-    public function setLocale($locale)
+    public function getDateType()
     {
-        throw new MethodNotImplementedException(__METHOD__);
+        return $this->datetype;
     }
 
-    public function getPattern()
+    public function setLocale($locale)
     {
-        return $this->pattern;
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function setPattern($pattern)
+    public function getErrorCode()
     {
-        if (null === $pattern) {
-            $patternParts = array();
-            if (self::NONE !== $this->datetype) {
-                $patternParts[] = $this->defaultDateFormats[$this->datetype];
-            }
-            if (self::NONE !== $this->timetype) {
-                $patternParts[] = $this->defaultTimeFormats[$this->timetype];
-            }
-            $pattern = implode(' ', $patternParts);
-        }
-
-        $this->pattern = $pattern;
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function getCalendar()
+    public function getErrorMessage()
     {
-        return self::GREGORIAN;
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function setCalendar()
+    public function getLocale()
     {
-        throw new MethodNotImplementedException(__METHOD__);
+        return 'en';
     }
 
-    public function getDateType()
+    public function getPattern()
     {
-        return $this->datetype;
+        return $this->pattern;
     }
 
     public function getTimeType()
@@ -266,43 +255,59 @@ class StubIntlDateFormatter
         return $this->timetype;
     }
 
-    public function getErrorCode()
+    public function getTimeZoneId()
     {
-        throw new MethodNotImplementedException(__METHOD__);
+        return $this->dateTimeZone->getName();
     }
 
-    public function getErrorMessage()
+    public function isLenient()
     {
         throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function getTimezoneId()
+    public function localtime($value, &$position = 0)
     {
-        return $this->dateTimeZone->getName();
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function setTimezoneId($timezoneId)
+    public function parse($value, &$position = 0)
     {
-        try {
-            $this->dateTimeZone = new \DateTimeZone($timezoneId);
-        } catch (\Exception $e) {
-            $this->dateTimeZone = new \DateTimeZone('UTC');
-        }
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function isLenient()
+    public function setCalendar()
     {
         throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function localtime($value, &$position = 0)
+    public function setLenient($lenient)
     {
         throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function parse($value, &$position = 0)
+    public function setPattern($pattern)
     {
-        throw new MethodNotImplementedException(__METHOD__);
+        if (null === $pattern) {
+            $patternParts = array();
+            if (self::NONE !== $this->datetype) {
+                $patternParts[] = $this->defaultDateFormats[$this->datetype];
+            }
+            if (self::NONE !== $this->timetype) {
+                $patternParts[] = $this->defaultTimeFormats[$this->timetype];
+            }
+            $pattern = implode(' ', $patternParts);
+        }
+
+        $this->pattern = $pattern;
+    }
+
+    public function setTimeZoneId($timeZoneId)
+    {
+        try {
+            $this->dateTimeZone = new \DateTimeZone($timeZoneId);
+        } catch (\Exception $e) {
+            $this->dateTimeZone = new \DateTimeZone('UTC');
+        }
     }
 
     static public function create($locale, $datetype, $timetype, $timezone = null, $calendar = null, $pattern = null)

+ 22 - 13
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -376,20 +376,20 @@ class StubIntlDateFormatterTest extends LocaleTestCase
     }
 
     /**
-    * @dataProvider timezoneIdProvider
+    * @dataProvider timeZoneIdProvider
     */
-    public function testGetTimezoneId($timezoneId)
+    public function testGetTimeZoneId($timeZoneId)
     {
-        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, $timezoneId);
-        $this->assertEquals($timezoneId, $formatter->getTimezoneId(), 'Check timezone id with stub implementation.');
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, $timeZoneId);
+        $this->assertEquals($timeZoneId, $formatter->getTimeZoneId(), 'Check timezone id with stub implementation.');
 
         if ($this->isIntlExtensionLoaded()) {
-            $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, $timezoneId);
-            $this->assertEquals($timezoneId, $formatter->getTimezoneId(), 'Check timezone id with intl extension.');
+            $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, $timeZoneId);
+            $this->assertEquals($timeZoneId, $formatter->getTimeZoneId(), 'Check timezone id with intl extension.');
         }
     }
 
-    public function timezoneIdProvider()
+    public function timeZoneIdProvider()
     {
         return array(
             array('Europe/Zurich'),
@@ -397,19 +397,19 @@ class StubIntlDateFormatterTest extends LocaleTestCase
         );
     }
 
-    public function testSetTimezoneId()
+    public function testSetTimeZoneId()
     {
         $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'UTC');
-        $this->assertEquals('UTC', $formatter->getTimezoneId(), 'Check timezone id with stub implementation.');
+        $this->assertEquals('UTC', $formatter->getTimeZoneId(), 'Check timezone id with stub implementation.');
 
-        $formatter->setTimezoneId('Europe/Zurich');
-        $this->assertEquals('Europe/Zurich', $formatter->getTimezoneId(), 'Check timezone id with intl extension.');
+        $formatter->setTimeZoneId('Europe/Zurich');
+        $this->assertEquals('Europe/Zurich', $formatter->getTimeZoneId(), 'Check timezone id with intl extension.');
 
         if ($this->isIntlExtensionLoaded()) {
             $formatter = new \IntlDateFormatter('en', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, 'UTC');
 
-            $formatter->setTimezoneId('Europe/Zurich');
-            $this->assertEquals('Europe/Zurich', $formatter->getTimezoneId(), 'Check timezone id with intl extension.');
+            $formatter->setTimeZoneId('Europe/Zurich');
+            $this->assertEquals('Europe/Zurich', $formatter->getTimeZoneId(), 'Check timezone id with intl extension.');
         }
     }
 
@@ -440,6 +440,15 @@ class StubIntlDateFormatterTest extends LocaleTestCase
         $formatter->isLenient();
     }
 
+    /**
+     * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
+     */
+    public function testSetLenient()
+    {
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
+        $formatter->setLenient(true);
+    }
+
     public function testStaticCreate()
     {
         $formatter = StubIntlDateFormatter::create('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);