|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\Doctrine\Tests\Form;
|
13 | 13 |
|
| 14 | +use Doctrine\DBAL\Types\Types; |
14 | 15 | use Doctrine\ORM\Mapping\ClassMetadata;
|
15 | 16 | use Doctrine\Persistence\ManagerRegistry;
|
16 | 17 | use Doctrine\Persistence\ObjectManager;
|
17 | 18 | use PHPUnit\Framework\TestCase;
|
18 | 19 | use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
|
19 | 20 | use Symfony\Component\Form\Guess\Guess;
|
| 21 | +use Symfony\Component\Form\Guess\TypeGuess; |
20 | 22 | use Symfony\Component\Form\Guess\ValueGuess;
|
21 | 23 |
|
22 | 24 | class DoctrineOrmTypeGuesserTest extends TestCase
|
23 | 25 | {
|
| 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 | + |
24 | 52 | /**
|
25 | 53 | * @dataProvider requiredProvider
|
26 | 54 | */
|
|
0 commit comments