|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Form\Tests\Extension\Core\Type; |
13 | 13 |
|
| 14 | +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; |
14 | 15 | use Symfony\Component\Form\ChoiceList\View\ChoiceView; |
15 | 16 | use Symfony\Component\Form\FormError; |
16 | 17 | use Symfony\Component\Form\FormInterface; |
|
19 | 20 |
|
20 | 21 | class DateTypeTest extends BaseTypeTestCase |
21 | 22 | { |
| 23 | + use ExpectDeprecationTrait; |
| 24 | + |
22 | 25 | public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateType'; |
23 | 26 |
|
24 | 27 | private $defaultTimezone; |
@@ -654,7 +657,7 @@ public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyEmpty() |
654 | 657 |
|
655 | 658 | public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled() |
656 | 659 | { |
657 | | - $form = $this->factory->create(static::TESTED_TYPE, new \DateTime(), [ |
| 660 | + $form = $this->factory->create(static::TESTED_TYPE, new \DateTime('now', new \DateTimeZone('UTC')), [ |
658 | 661 | 'model_timezone' => 'UTC', |
659 | 662 | 'view_timezone' => 'UTC', |
660 | 663 | 'widget' => 'choice', |
@@ -1112,6 +1115,35 @@ public function testSubmitStringWithCustomInputFormat() |
1112 | 1115 | $this->assertSame('14/01/2018', $form->getData()); |
1113 | 1116 | } |
1114 | 1117 |
|
| 1118 | + /** |
| 1119 | + * @group legacy |
| 1120 | + */ |
| 1121 | + public function testDateTimeInputTimezoneNotMatchingModelTimezone() |
| 1122 | + { |
| 1123 | + $this->expectDeprecation('Since symfony/form 6.4: Using a "DateTime" instance with a timezone ("UTC") not matching the configured model timezone "Europe/Berlin" is deprecated.'); |
| 1124 | + // $this->expectException(LogicException::class); |
| 1125 | + // $this->expectExceptionMessage('Using a "DateTime" instance with a timezone ("UTC") not matching the configured model timezone "Europe/Berlin" is not supported.'); |
| 1126 | + |
| 1127 | + $this->factory->create(static::TESTED_TYPE, new \DateTime('now', new \DateTimeZone('UTC')), [ |
| 1128 | + 'model_timezone' => 'Europe/Berlin', |
| 1129 | + ]); |
| 1130 | + } |
| 1131 | + |
| 1132 | + /** |
| 1133 | + * @group legacy |
| 1134 | + */ |
| 1135 | + public function testDateTimeImmutableInputTimezoneNotMatchingModelTimezone() |
| 1136 | + { |
| 1137 | + $this->expectDeprecation('Since symfony/form 6.4: Using a "DateTimeImmutable" instance with a timezone ("UTC") not matching the configured model timezone "Europe/Berlin" is deprecated.'); |
| 1138 | + // $this->expectException(LogicException::class); |
| 1139 | + // $this->expectExceptionMessage('Using a "DateTimeImmutable" instance with a timezone ("UTC") not matching the configured model timezone "Europe/Berlin" is not supported.'); |
| 1140 | + |
| 1141 | + $this->factory->create(static::TESTED_TYPE, new \DateTimeImmutable('now', new \DateTimeZone('UTC')), [ |
| 1142 | + 'input' => 'datetime_immutable', |
| 1143 | + 'model_timezone' => 'Europe/Berlin', |
| 1144 | + ]); |
| 1145 | + } |
| 1146 | + |
1115 | 1147 | protected function getTestOptions(): array |
1116 | 1148 | { |
1117 | 1149 | return ['widget' => 'choice']; |
|
0 commit comments