Ver Fonte

[Form] Changed to a CreateException when the 'format' option is invalid
* Updated DateTypeTest also

Matthieu Vachon há 14 anos atrás
pai
commit
436cb95223

+ 7 - 5
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -14,6 +14,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormBuilder;
+use Symfony\Component\Form\Exception\CreationException;
+use Symfony\Component\Form\Exception\FormException;
 use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
 use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
 use Symfony\Component\Form\FormView;
@@ -29,26 +31,26 @@ class DateType extends AbstractType
     {
         $format = $options['format'];
         $pattern = null;
-        
+
         $allowedFormatOptionValues = array(
             \IntlDateFormatter::FULL,
             \IntlDateFormatter::LONG,
             \IntlDateFormatter::MEDIUM,
             \IntlDateFormatter::SHORT,
         );
-        
+
         // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
         if (!in_array($format, $allowedFormatOptionValues, true)) {
             if (is_string($format)) {
                 $defaultOptions = $this->getDefaultOptions($options);
-                
+
                 $format = $defaultOptions['format'];
                 $pattern = $options['format'];
             } else {
-                throw new FormException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
+                throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
             }
         }
-        
+
         $formatter = new \IntlDateFormatter(
             \Locale::getDefault(),
             $format,

+ 2 - 2
tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php

@@ -269,7 +269,7 @@ class DateTypeTest extends LocalizedTestCase
     }
 
     /**
-     * @expectedException Symfony\Component\Form\Exception\FormException
+     * @expectedException Symfony\Component\Form\Exception\CreationException
      */
     public function testValidateFormatOptionGivenWrongConstants()
     {
@@ -279,7 +279,7 @@ class DateTypeTest extends LocalizedTestCase
     }
 
     /**
-     * @expectedException Symfony\Component\Form\Exception\FormException
+     * @expectedException Symfony\Component\Form\Exception\CreationException
      */
     public function testValidateFormatOptionGivenArrayValue()
     {