Skip to content

Commit f4d7571

Browse files
committed
Fix that MillisecondTimestamp converts null to int
1 parent 8dbaf9f commit f4d7571

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/Behavior/MillisecondTimestamp.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public function fromDb($value, $key, $context)
2424

2525
public function toDb($value, $key, $context)
2626
{
27+
if ($value === null) {
28+
return null;
29+
}
30+
2731
if (is_numeric($value)) {
2832
return (int) ($value * 1000.0);
2933
}

tests/MillisecondTimestampBehaviorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public function testFromDbReturnsNullWhenNullIsPassed()
1515
$this->assertNull((new MillisecondTimestamp([]))->fromDb(null, 'key', null));
1616
}
1717

18+
public function testToDbReturnsNullWhenNullIsPassed()
19+
{
20+
$this->assertNull((new MillisecondTimestamp([]))->toDb(null, 'key', null));
21+
}
22+
1823
public function testToDbReturnsUtcTimestampWithNonUtcInput()
1924
{
2025
$sometime = DateTime::createFromFormat(

0 commit comments

Comments
 (0)