Skip to content

Commit

Permalink
test: add test for datetime with key but without format
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed May 21, 2022
1 parent b75adb7 commit 427a291
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mapper/Object/DateTimeObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function build(array $arguments): DateTimeInterface
$format = null;

if (is_array($datetime)) {
$format = $datetime['format'];
$format = $datetime['format'] ?? null;
$datetime = $datetime['datetime'];
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Integration/Mapping/Object/DateTimeMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function test_datetime_properties_are_converted_properly(): void
$dateTimeInterface = new DateTimeImmutable('@' . $this->buildRandomTimestamp());
$dateTimeImmutable = new DateTimeImmutable('@' . $this->buildRandomTimestamp());
$dateTimeFromTimestamp = $this->buildRandomTimestamp();
$dateTimeFromTimestampWithOutFormat = [
'datetime' => $this->buildRandomTimestamp(),
];
$dateTimeFromTimestampWithFormat = [
'datetime' => $this->buildRandomTimestamp(),
'format' => 'U',
Expand All @@ -37,6 +40,7 @@ public function test_datetime_properties_are_converted_properly(): void
'dateTimeInterface' => $dateTimeInterface,
'dateTimeImmutable' => $dateTimeImmutable,
'dateTimeFromTimestamp' => $dateTimeFromTimestamp,
'dateTimeFromTimestampWithOutFormat' => $dateTimeFromTimestampWithOutFormat,
'dateTimeFromTimestampWithFormat' => $dateTimeFromTimestampWithFormat,
'dateTimeFromAtomFormat' => $dateTimeFromAtomFormat,
'dateTimeFromArray' => $dateTimeFromArray,
Expand All @@ -53,6 +57,7 @@ public function test_datetime_properties_are_converted_properly(): void
self::assertEquals($dateTimeImmutable, $result->dateTimeImmutable);
self::assertEquals(new DateTimeImmutable("@$dateTimeFromTimestamp"), $result->dateTimeFromTimestamp);
self::assertEquals(new DateTimeImmutable("@{$dateTimeFromTimestampWithFormat['datetime']}"), $result->dateTimeFromTimestampWithFormat);
self::assertEquals(new DateTimeImmutable("@{$dateTimeFromTimestampWithOutFormat['datetime']}"), $result->dateTimeFromTimestampWithOutFormat);
self::assertEquals(DateTimeImmutable::createFromFormat(DATE_ATOM, $dateTimeFromAtomFormat), $result->dateTimeFromAtomFormat);
self::assertEquals(DateTimeImmutable::createFromFormat($dateTimeFromArray['format'], $dateTimeFromArray['datetime']), $result->dateTimeFromArray);
self::assertEquals(DateTimeImmutable::createFromFormat(DateTimeObjectBuilder::DATE_MYSQL, $mysqlDate), $result->mysqlDate);
Expand Down Expand Up @@ -134,6 +139,8 @@ final class AllDateTimeValues

public DateTime $dateTimeFromTimestamp;

public DateTime $dateTimeFromTimestampWithOutFormat;

public DateTime $dateTimeFromTimestampWithFormat;

public DateTimeInterface $dateTimeFromAtomFormat;
Expand Down

0 comments on commit 427a291

Please sign in to comment.