Skip to content

Commit e972224

Browse files
Merge branch '5.0' into 5.1
* 5.0: Fix test that fails on old distros Fix: compatibility with phpunit 9.3 [DoctrineBridge] work around Connection::ping() deprecation [MimeType] Duplicated MimeType due to PHP Bug [DI] fix parsing of argument type=binary in xml fix guessing form types for DateTime types fix handling typed properties as constraint options Fix the 'supports' method argument type of the security voter Use the driverConnection executeUpdate method
2 parents b4aaf33 + 69ed73e commit e972224

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
return [

0 commit comments

Comments
 (0)