Skip to content

Commit f56e263

Browse files
Merge branch '3.4' into 4.4
* 3.4: [MimeType] Duplicated MimeType due to PHP Bug fix guessing form types for DateTime types fix handling typed properties as constraint options
2 parents 828d26a + ebd2d24 commit f56e263

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Extension/Validator/ValidatorTypeGuesser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function guessTypeForConstraint(Constraint $constraint)
9797
case 'long':
9898
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\IntegerType', [], Guess::MEDIUM_CONFIDENCE);
9999

100+
case \DateTime::class:
100101
case '\DateTime':
101102
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::MEDIUM_CONFIDENCE);
102103

Tests/Extension/Validator/ValidatorTypeGuesserTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Validator;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
16+
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
17+
use Symfony\Component\Form\Extension\Core\Type\DateType;
18+
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
19+
use Symfony\Component\Form\Extension\Core\Type\NumberType;
20+
use Symfony\Component\Form\Extension\Core\Type\TextType;
1521
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
1622
use Symfony\Component\Form\Guess\Guess;
23+
use Symfony\Component\Form\Guess\TypeGuess;
1724
use Symfony\Component\Form\Guess\ValueGuess;
25+
use Symfony\Component\Validator\Constraint;
1826
use Symfony\Component\Validator\Constraints\Email;
1927
use Symfony\Component\Validator\Constraints\File;
2028
use Symfony\Component\Validator\Constraints\IsTrue;
@@ -60,6 +68,35 @@ protected function setUp(): void
6068
$this->guesser = new ValidatorTypeGuesser($this->metadataFactory);
6169
}
6270

71+
/**
72+
* @dataProvider guessTypeProvider
73+
*/
74+
public function testGuessType(Constraint $constraint, TypeGuess $guess)
75+
{
76+
$this->metadata->addPropertyConstraint(self::TEST_PROPERTY, $constraint);
77+
78+
$this->assertEquals($guess, $this->guesser->guessType(self::TEST_CLASS, self::TEST_PROPERTY));
79+
}
80+
81+
public function guessTypeProvider()
82+
{
83+
return [
84+
[new Type('array'), new TypeGuess(CollectionType::class, [], Guess::MEDIUM_CONFIDENCE)],
85+
[new Type('bool'), new TypeGuess(CheckboxType::class, [], Guess::MEDIUM_CONFIDENCE)],
86+
[new Type('boolean'), new TypeGuess(CheckboxType::class, [], Guess::MEDIUM_CONFIDENCE)],
87+
[new Type('double'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
88+
[new Type('float'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
89+
[new Type('numeric'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
90+
[new Type('real'), new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE)],
91+
[new Type('int'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
92+
[new Type('integer'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
93+
[new Type('long'), new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE)],
94+
[new Type('string'), new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE)],
95+
[new Type(\DateTime::class), new TypeGuess(DateType::class, [], Guess::MEDIUM_CONFIDENCE)],
96+
[new Type('\DateTime'), new TypeGuess(DateType::class, [], Guess::MEDIUM_CONFIDENCE)],
97+
];
98+
}
99+
63100
public function guessRequiredProvider()
64101
{
65102
$allowEmptyString = property_exists(Length::class, 'allowEmptyString') ? ['allowEmptyString' => true] : [];

0 commit comments

Comments
 (0)