fix guessing form types for DateTime types
This commit is contained in:
parent
9660e6b1e2
commit
9ba90bf1f8
@ -97,6 +97,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
case 'long':
|
case 'long':
|
||||||
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\IntegerType', [], Guess::MEDIUM_CONFIDENCE);
|
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\IntegerType', [], Guess::MEDIUM_CONFIDENCE);
|
||||||
|
|
||||||
|
case \DateTime::class:
|
||||||
case '\DateTime':
|
case '\DateTime':
|
||||||
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::MEDIUM_CONFIDENCE);
|
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::MEDIUM_CONFIDENCE);
|
||||||
|
|
||||||
|
@ -12,9 +12,17 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Validator;
|
namespace Symfony\Component\Form\Tests\Extension\Validator;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
|
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
|
||||||
use Symfony\Component\Form\Guess\Guess;
|
use Symfony\Component\Form\Guess\Guess;
|
||||||
|
use Symfony\Component\Form\Guess\TypeGuess;
|
||||||
use Symfony\Component\Form\Guess\ValueGuess;
|
use Symfony\Component\Form\Guess\ValueGuess;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
use Symfony\Component\Validator\Constraints\Email;
|
use Symfony\Component\Validator\Constraints\Email;
|
||||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Constraints\Length;
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
@ -59,6 +67,35 @@ class ValidatorTypeGuesserTest extends TestCase
|
|||||||
$this->guesser = new ValidatorTypeGuesser($this->metadataFactory);
|
$this->guesser = new ValidatorTypeGuesser($this->metadataFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider guessTypeProvider
|
||||||
|
*/
|
||||||
|
public function testGuessType(Constraint $constraint, TypeGuess $guess)
|
||||||
|
{
|
||||||
|
$this->metadata->addPropertyConstraint(self::TEST_PROPERTY, $constraint);
|
||||||
|
|
||||||
|
$this->assertEquals($guess, $this->guesser->guessType(self::TEST_CLASS, self::TEST_PROPERTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function guessTypeProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[new Type('array'), new TypeGuess(CollectionType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('bool'), new TypeGuess(CheckboxType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('boolean'), new TypeGuess(CheckboxType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('double'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('float'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('numeric'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('real'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('int'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('integer'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('long'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('string'), new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE)],
|
||||||
|
[new Type(\DateTime::class), new TypeGuess(DateType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
[new Type('\DateTime'), new TypeGuess(DateType::class, [], Guess::MEDIUM_CONFIDENCE)],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function guessRequiredProvider()
|
public function guessRequiredProvider()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Reference in New Issue
Block a user