Quellcode durchsuchen

[Locale] refactoring and some more tests

Igor Wiedler vor 14 Jahren
Ursprung
Commit
69b38faff7

+ 9 - 15
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Locale\Stub;
 
-use Symfony\Component\Locale\Locale;
+use Symfony\Component\Locale\Exception\MethodNotImplementedException;
 
 /**
  * Provides a stub IntlDateFormatter for the 'en' locale.
@@ -225,19 +225,14 @@ class StubIntlDateFormatter
         return 'en';
     }
 
-    public function getPattern()
-    {
-        return $this->pattern;
-    }
-
-    public function getCalendar()
+    public function setLocale($locale)
     {
-        return self::GREGORIAN;
+        throw new MethodNotImplementedException(__METHOD__);
     }
 
-    public function setLocale($locale)
+    public function getPattern()
     {
-        $this->throwMethodNotImplementException(__METHOD__);
+        return $this->pattern;
     }
 
     public function setPattern($pattern)
@@ -256,14 +251,13 @@ class StubIntlDateFormatter
         $this->pattern = $pattern;
     }
 
-    public function setCalendar()
+    public function getCalendar()
     {
-        $this->throwMethodNotImplementException(__METHOD__);
+        return self::GREGORIAN;
     }
 
-    private function throwMethodNotImplementException($methodName)
+    public function setCalendar()
     {
-        $message = sprintf('The %s::%s() is not implemented. Install the intl extension for full localization capabilities.', __CLASS__, $methodName);
-        throw new \RuntimeException($message);
+        throw new MethodNotImplementedException(__METHOD__);
     }
 }

+ 31 - 3
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -302,18 +302,46 @@ class StubIntlDateFormatterTest extends LocaleTestCase
         );
     }
 
+    public function testGetPattern()
+    {
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, StubIntlDateFormatter::GREGORIAN, 'UTC', 'yyyy-MM-dd');
+        $this->assertEquals('yyyy-MM-dd', $formatter->getPattern());
+    }
+
+    public function testSetPattern()
+    {
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
+        $formatter->setPattern('yyyy-MM-dd');
+        $this->assertEquals('yyyy-MM-dd', $formatter->getPattern());
+    }
+
+    public function testGetLocale()
+    {
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
+        $this->assertEquals('en', $formatter->getLocale());
+    }
+
     /**
-     * @expectedException RuntimeException
+     * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
      */
+    public function testSetLocale()
+    {
+        $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
+        $formatter->setLocale('pt_BR');
+    }
+
     public function testGetCalendar()
     {
         $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
-        $formatter->setCalendar(StubIntlDateFormatter::GREGORIAN);
+        $this->assertEquals(StubIntlDateFormatter::GREGORIAN, $formatter->getCalendar());
     }
 
+    /**
+     * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
+     */
     public function testSetCalendar()
     {
         $formatter = new StubIntlDateFormatter('en', StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE);
-        $this->assertEquals(StubIntlDateFormatter::GREGORIAN, $formatter->getCalendar());
+        $formatter->setCalendar(StubIntlDateFormatter::GREGORIAN);
     }
 }