File tree Expand file tree Collapse file tree 4 files changed +18
-17
lines changed
src/Symfony/Bridge/Doctrine
DependencyInjection/CompilerPass
DependencyInjection/CompilerPass Expand file tree Collapse file tree 4 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public function process(ContainerBuilder $container): void
3030
3131 $ typeDefinition = $ container ->getParameter ('doctrine.dbal.connection_factory.types ' );
3232
33- if (!isset ($ typeDefinition ['date_point ' ])) {
33+ if (is_array ( $ typeDefinition ) && !isset ($ typeDefinition ['date_point ' ])) {
3434 $ typeDefinition ['date_point ' ] = ['class ' => DatePointType::class];
3535 }
3636
Original file line number Diff line number Diff line change 1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Bridge \Doctrine \DependencyInjection \CompilerPass \RegisterDatePointTypePass ;
1616use Symfony \Bridge \Doctrine \Types \DatePointType ;
17+ use Symfony \Component \Clock \DatePoint ;
1718use Symfony \Component \DependencyInjection \ContainerBuilder ;
1819
1920class RegisterDatePointTypePassTest extends TestCase
2021{
22+ protected function setUp (): void
23+ {
24+ if (!class_exists (DatePoint::class)) {
25+ self ::markTestSkipped ('The DatePoint class is not available. ' );
26+ }
27+ }
28+
2129 public function testRegistered ()
2230 {
2331 $ container = new ContainerBuilder ();
@@ -30,12 +38,4 @@ public function testRegistered()
3038 ];
3139 $ this ->assertSame ($ expected , $ container ->getParameter ('doctrine.dbal.connection_factory.types ' ));
3240 }
33-
34- public function testRegisteredDontFail ()
35- {
36- $ container = new ContainerBuilder ();
37- (new RegisterDatePointTypePass ())->process ($ container );
38-
39- $ this ->expectNotToPerformAssertions ();
40- }
4141}
Original file line number Diff line number Diff line change 1414use DateTimeImmutable ;
1515use Doctrine \DBAL \Platforms \AbstractPlatform ;
1616use Doctrine \DBAL \Platforms \MariaDBPlatform ;
17- use Doctrine \DBAL \Platforms \MySQLPlatform ;
1817use Doctrine \DBAL \Platforms \PostgreSQLPlatform ;
1918use Doctrine \DBAL \Platforms \SqlitePlatform ;
2019use Doctrine \DBAL \Types \ConversionException ;
@@ -39,10 +38,10 @@ public static function setUpBeforeClass(): void
3938
4039 protected function setUp (): void
4140 {
42- $ this ->type = Type::getType (DatePointType::NAME );
4341 if (!class_exists (DatePoint::class)) {
4442 self ::markTestSkipped ('The DatePoint class is not available. ' );
4543 }
44+ $ this ->type = Type::getType (DatePointType::NAME );
4645 }
4746
4847 public function testDatePointConvertsToDatabaseValue ()
@@ -57,7 +56,6 @@ public function testDatePointConvertsToDatabaseValue()
5756
5857 public function testDatePointConvertsToPHPValue ()
5958 {
60-
6159 $ datePoint = new DatePoint ();
6260 $ actual = $ this ->type ->convertToPHPValue ($ datePoint , new SqlitePlatform ());
6361
Original file line number Diff line number Diff line change 1313
1414use DateTimeInterface ;
1515use Doctrine \DBAL \Platforms \AbstractPlatform ;
16- use Doctrine \DBAL \Types \ConversionException ;
1716use Doctrine \DBAL \Types \DateTimeImmutableType ;
1817use Symfony \Component \Clock \DatePoint ;
1918
2019final class DatePointType extends DateTimeImmutableType
2120{
2221 public const NAME = 'date_point ' ;
2322
23+ /**
24+ * @param T $value
25+ *
26+ * @return (T is null ? null : DatePoint)
27+ *
28+ * @template T
29+ */
2430 public function convertToPHPValue (mixed $ value , AbstractPlatform $ platform ): ?DatePoint
2531 {
2632 if (null === $ value || $ value instanceof DatePoint) {
2733 return $ value ;
2834 }
2935
3036 $ value = parent ::convertToPHPValue ($ value , $ platform );
31- if ($ value instanceof DateTimeInterface) {
32- return DatePoint::createFromInterface ($ value );
33- }
3437
35- throw new ConversionException ( );
38+ return DatePoint:: createFromInterface ( $ value );
3639 }
3740
3841 public function getName (): string
You can’t perform that action at this time.
0 commit comments