19declare(strict_types=1);
27use PHPUnit\Framework\TestCase;
28use PHPUnit\Framework\Attributes\DataProvider;
35 protected function setUp(): void
40 #[DataProvider('DateTimeTransformationDataProvider')]
43 $transformedValue = $this->transformation->transform($originVal);
44 $this->assertIsObject($transformedValue);
45 $this->assertInstanceOf(DateTimeImmutable::class, $transformedValue);
46 $this->assertEquals($expectedVal, $transformedValue);
55 $gmt_format =
'D, d M Y H:i:s \G\M\T';
56 $test_gmt_date_time =
'Mon, 06 Jul 2020 12:23:05 GMT';
58 $exptected = DateTimeImmutable::createFromFormat(
63 $actual = $this->transformation->transform($test_gmt_date_time);
64 $this->assertEquals($exptected, $actual);
66 $actual = $actual->setTimezone(
new DateTimeZone(
'Europe/Berlin'));
68 $this->assertSame(
'Mon, 06 Jul 2020 14:23:05 GMT', $actual->format($gmt_format));
69 $this->assertEquals($exptected, $actual);
72 #[DataProvider('TransformationFailureDataProvider')]
75 $this->expectException(ConstraintViolationException::class);
76 $this->transformation->transform($failingValue);
81 $now =
new DateTimeImmutable();
83 'datetime' => [$now, $now],
85 '2020-07-06T12:23:05+0000',
86 DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601,
'2020-07-06T12:23:05+0000')
89 '2020-07-06T12:23:05+00:00',
90 DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM,
'2020-07-06T12:23:05+00:00')
93 '2020-07-06T12:23:05.000+00:00',
94 DateTimeImmutable::createFromFormat(
95 DateTimeInterface::RFC3339_EXTENDED,
96 '2020-07-06T12:23:05.000+00:00'
100 'Monday, 06-Jul-2020 12:23:05 GMT+0000',
101 DateTimeImmutable::createFromFormat(DateTimeInterface::COOKIE,
'Monday, 06-Jul-2020 12:23:05 GMT+0000')
104 'Mon, 06 Jul 20 12:23:05 +0000',
105 DateTimeImmutable::createFromFormat(DateTimeInterface::RFC822,
'Mon, 06 Jul 20 12:23:05 +0000')
108 'Mon, 06 Jul 2020 12:23:05 GMT',
109 DateTimeImmutable::createFromFormat(
'D, d M Y H:i:s \G\M\T',
'Mon, 06 Jul 2020 12:23:05 GMT')
111 'unix_timestamp' => [
113 DateTimeImmutable::createFromFormat(
114 DateTimeInterface::ISO8601,
115 '1985-04-05T13:37:42+0000'
118 'unix_timestamp_float' => [
120 DateTimeImmutable::createFromFormat(
121 DateTimeInterface::ISO8601,
122 '1985-04-05T13:37:42+0000'
131 'no_matching_string_format' => [
'hello']