Skip to content

Commit 11c8761

Browse files
committed
bug #39498 [DoctrineBridge] Guess correct form types for DATE_IMMUTABLE and DATETIME_IMMUTABLE (guillaume-sainthillier)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [DoctrineBridge] Guess correct form types for DATE_IMMUTABLE and DATETIME_IMMUTABLE | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39468 | License | MIT | Doc PR | - Rebased PR #39469 Fixes #39468 related to Doctrine Form Type Guesser with DateImmutable type Commits ------- 238d318e34 [DoctrineBridge] Guess correct form types for DATE_IMMUTABLE and DATETIME_IMMUTABLE
2 parents 9895bea + f62a865 commit 11c8761

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Form/DoctrineOrmTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function guessType(string $class, string $property)
6161
case Types::DATETIMETZ_MUTABLE:
6262
case 'vardatetime':
6363
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE);
64-
case Types::DATE_IMMUTABLE:
64+
case Types::DATETIME_IMMUTABLE:
6565
case Types::DATETIMETZ_IMMUTABLE:
6666
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE);
6767
case Types::DATEINTERVAL:

Tests/Form/DoctrineOrmTypeGuesserTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,44 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Form;
1313

14+
use Doctrine\DBAL\Types\Types;
1415
use Doctrine\ORM\Mapping\ClassMetadata;
1516
use Doctrine\Persistence\ManagerRegistry;
1617
use Doctrine\Persistence\ObjectManager;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
1920
use Symfony\Component\Form\Guess\Guess;
21+
use Symfony\Component\Form\Guess\TypeGuess;
2022
use Symfony\Component\Form\Guess\ValueGuess;
2123

2224
class DoctrineOrmTypeGuesserTest extends TestCase
2325
{
26+
/**
27+
* @dataProvider requiredType
28+
*/
29+
public function testTypeGuesser(string $type, $expected)
30+
{
31+
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
32+
$classMetadata->fieldMappings['field'] = true;
33+
$classMetadata->expects($this->once())->method('getTypeOfField')->with('field')->willReturn($type);
34+
35+
$this->assertEquals($expected, $this->getGuesser($classMetadata)->guessType('TestEntity', 'field'));
36+
}
37+
38+
public function requiredType()
39+
{
40+
yield [Types::DATE_IMMUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE)];
41+
yield [Types::DATE_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::HIGH_CONFIDENCE)];
42+
43+
yield [Types::TIME_IMMUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE)];
44+
yield [Types::TIME_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', [], Guess::HIGH_CONFIDENCE)];
45+
46+
yield [Types::DATETIME_IMMUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE)];
47+
yield [Types::DATETIMETZ_IMMUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE)];
48+
yield [Types::DATETIME_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE)];
49+
yield [Types::DATETIMETZ_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE)];
50+
}
51+
2452
/**
2553
* @dataProvider requiredProvider
2654
*/

0 commit comments

Comments
 (0)