File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ public static function coerceValueToColumn(
215
215
$ value .= ' 00:00:00 ' ;
216
216
}
217
217
218
- if ($ value[ 0 ] === '- ' || $ value === '' ) {
218
+ if ($ value === '' || $ value[ 0 ] === '- ' ) {
219
219
$ value = '0000-00-00 00:00:00 ' ;
220
220
} elseif (\preg_match (
221
221
'/^([0-9]{2,4}-[0-1][0-9]-[0-3][0-9]|[0-9]+)$/ ' ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Vimeo \MysqlEngine \Tests ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Vimeo \MysqlEngine \DataIntegrity ;
7
+ use Vimeo \MysqlEngine \FakePdoInterface ;
8
+ use Vimeo \MysqlEngine \Php7 \FakePdo ;
9
+ use Vimeo \MysqlEngine \Schema \Column \DateTime ;
10
+ use const PHP_MAJOR_VERSION ;
11
+
12
+ class DataIntegrityTest extends TestCase
13
+ {
14
+
15
+ public function testEmptyDateTimeColumnShouldReturnDefaultDate ()
16
+ {
17
+ $ dateTimeColumn = new DateTime ();
18
+
19
+ $ result = DataIntegrity::coerceValueToColumn ($ this ->getPdo (), $ dateTimeColumn , '' );
20
+
21
+ $ this ->assertEquals ('0000-00-00 00:00:00 ' , $ result );
22
+ }
23
+
24
+ private static function getPdo (): FakePdoInterface
25
+ {
26
+ if (PHP_MAJOR_VERSION === 8 ) {
27
+ return new \Vimeo \MysqlEngine \Php8 \FakePdo ('mysql:foo;dbname=test; ' );
28
+ }
29
+
30
+ return new FakePdo ('mysql:foo;dbname=test; ' );
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments