ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
DateTimeTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 
30 {
32 
33  protected function setUp(): void
34  {
35  $this->transformation = new DateTimeTransformation();
36  }
37 
43  public function testDateTimeISOTransformation($originVal, DateTimeImmutable $expectedVal): void
44  {
45  $transformedValue = $this->transformation->transform($originVal);
46  $this->assertIsObject($transformedValue);
47  $this->assertInstanceOf(DateTimeImmutable::class, $transformedValue);
48  $this->assertEquals($expectedVal, $transformedValue);
49  }
50 
55  public function testTransformIsInvalid(string $failingValue): void
56  {
57  $this->expectException(ConstraintViolationException::class);
58  $this->transformation->transform($failingValue);
59  }
60 
61  public function DateTimeTransformationDataProvider(): array
62  {
63  $now = new DateTimeImmutable();
64  return [
65  'datetime' => [$now, $now],
66  'iso8601' => ['2020-07-06T12:23:05+0000',
67  DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, '2020-07-06T12:23:05+0000')],
68  'atom' => ['2020-07-06T12:23:05+00:00',
69  DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM, '2020-07-06T12:23:05+00:00')],
70  'rfc3339_ext' => ['2020-07-06T12:23:05.000+00:00',
71  DateTimeImmutable::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, '2020-07-06T12:23:05.000+00:00')],
72  'cookie' => ['Monday, 06-Jul-2020 12:23:05 GMT+0000',
73  DateTimeImmutable::createFromFormat(DateTimeInterface::COOKIE, 'Monday, 06-Jul-2020 12:23:05 GMT+0000')],
74  'rfc822' => ['Mon, 06 Jul 20 12:23:05 +0000',
75  DateTimeImmutable::createFromFormat(DateTimeInterface::RFC822, 'Mon, 06 Jul 20 12:23:05 +0000')],
76  'rfc7231' => ['Mon, 06 Jul 2020 12:23:05 GMT',
77  DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, 'Mon, 06 Jul 2020 12:23:05 GMT')],
78  'unix_timestamp' => [481556262, DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, '1985-04-05T13:37:42+0000')],
79  'unix_timestamp_float' => [481556262.4, DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, '1985-04-05T13:37:42+0000')]
80  ];
81  }
82 
83  public function TransformationFailureDataProvider(): array
84  {
85  return [
86  'no_matching_string_format' => ['hello']
87  ];
88  }
89 }
testDateTimeISOTransformation($originVal, DateTimeImmutable $expectedVal)
DateTimeTransformationDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Transform date format to DateTimeImmutable Please note:
testTransformIsInvalid(string $failingValue)
TransformationFailureDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...