diff --git a/src/DataIntegrity.php b/src/DataIntegrity.php index 035e0eb5..677de218 100644 --- a/src/DataIntegrity.php +++ b/src/DataIntegrity.php @@ -215,7 +215,7 @@ public static function coerceValueToColumn( $value .= ' 00:00:00'; } - if ($value[0] === '-' || $value === '') { + if ($value === '' || $value[0] === '-') { $value = '0000-00-00 00:00:00'; } elseif (\preg_match( '/^([0-9]{2,4}-[0-1][0-9]-[0-3][0-9]|[0-9]+)$/', diff --git a/tests/DataIntegrityTest.php b/tests/DataIntegrityTest.php new file mode 100644 index 00000000..27143d4c --- /dev/null +++ b/tests/DataIntegrityTest.php @@ -0,0 +1,32 @@ +getPdo(), $dateTimeColumn, ''); + + $this->assertEquals('0000-00-00 00:00:00', $result); + } + + private static function getPdo(): FakePdoInterface + { + if (PHP_MAJOR_VERSION === 8) { + return new \Vimeo\MysqlEngine\Php8\FakePdo('mysql:foo;dbname=test;'); + } + + return new FakePdo('mysql:foo;dbname=test;'); + } +}