Skip to content

Commit 6a48277

Browse files
committed
Update test to match style
1 parent 2358f71 commit 6a48277

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Crell\Serde\Records;
6+
7+
use DateTimeInterface;
8+
9+
class DateTimeInterfaceExample {
10+
public function __construct(
11+
public DateTimeInterface $interfaceProperty,
12+
) {}
13+
}

tests/SerdeTestCases.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Crell\Serde\Records\ClassWithReducibleProperty;
2727
use Crell\Serde\Records\CompoundTypes;
2828
use Crell\Serde\Records\DateTimeExample;
29+
use Crell\Serde\Records\DateTimeInterfaceExample;
2930
use Crell\Serde\Records\DictionaryKeyTypes;
3031
use Crell\Serde\Records\Drupal\EmailItem;
3132
use Crell\Serde\Records\Drupal\FieldItemList;
@@ -339,6 +340,11 @@ public static function round_trip_examples(): iterable
339340
arrayMap: ['a' => [1, 2, 3]],
340341
),
341342
];
343+
yield 'datetimeinterface_type' => [
344+
'data' => new DateTimeInterfaceExample(
345+
interfaceProperty: new \DateTimeImmutable('2025-12-25 12:34:56.789'),
346+
),
347+
];
342348
}
343349

344350
public static function value_object_flatten_examples(): \Generator
@@ -1059,27 +1065,6 @@ public function datetime_fields_support_custom_output_format(): void
10591065
self::assertEquals($expected, $result);
10601066
}
10611067

1062-
#[Test]
1063-
public function datetime_field_can_be_datetimeinterface(): void
1064-
{
1065-
$s = new SerdeCommon(formatters: $this->formatters);
1066-
1067-
$timeString = '2025-12-25 12:34:56.789';
1068-
$stampImmutable = new \DateTimeImmutable($timeString);
1069-
1070-
$data = new class($stampImmutable) {
1071-
public function __construct(public readonly \DateTimeInterface $stamp) {}
1072-
};
1073-
1074-
$serialized = $s->serialize($data, $this->format);
1075-
1076-
$this->validateSerialized($serialized, __FUNCTION__);
1077-
1078-
$result = $s->deserialize($serialized, from: $this->format, to: get_class($data));
1079-
1080-
self::assertEquals($data, $result);
1081-
}
1082-
10831068
#[Test]
10841069
public function unixtime_fields_in_range_are_supported(): void
10851070
{

0 commit comments

Comments
 (0)