ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
DateTimeTransformationTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
3 
5 
6 require_once('./libs/composer/vendor/autoload.php');
7 
11 
17 {
18  private $transformation;
19 
20  public function setUp() : void
21  {
22  $this->transformation = new DateTimeTransformation();
23  }
24 
30  public function testDateTimeISOTransformation($originVal, $expectedVal)
31  {
32  $transformedValue = $this->transformation->transform($originVal);
33  $this->assertIsObject($transformedValue);
34  $this->assertInstanceOf(\DateTimeImmutable::class, $transformedValue);
35  $this->assertEquals($expectedVal, $transformedValue);
36  }
37 
42  public function testTransformIsInvalid($failingValue)
43  {
44  $this->expectException(ConstraintViolationException::class);
45  $this->transformation->transform($failingValue);
46  }
47 
49  {
50  $now = new \DateTimeImmutable();
51  return [
52  'datetime' => [$now, $now],
53  'iso8601' => ['2020-07-06T12:23:05+0000',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::ISO8601, '2020-07-06T12:23:05+0000')],
54  'atom' => ['2020-07-06T12:23:05+00:00',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, '2020-07-06T12:23:05+00:00')],
55  'rfc3339_ext' => ['2020-07-06T12:23:05.000+00:00',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC3339_EXTENDED, '2020-07-06T12:23:05.000+00:00')],
56  'cookie' => ['Monday, 06-Jul-2020 12:23:05 GMT+0000',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::COOKIE, 'Monday, 06-Jul-2020 12:23:05 GMT+0000')],
57  'rfc822' => ['Mon, 06 Jul 20 12:23:05 +0000',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC822, 'Mon, 06 Jul 20 12:23:05 +0000')],
58  'rfc7231' => ['Mon, 06 Jul 2020 12:23:05 GMT',\DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC7231, 'Mon, 06 Jul 2020 12:23:05 GMT')],
59  'unix_timestamp' => [481556262, \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ISO8601, '1985-04-05T13:37:42+0000')],
60  'unix_timestamp_float' => [481556262.4, \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ISO8601, '1985-04-05T13:37:42+0000')]
61  ];
62  }
63 
65  {
66  return [
67  'no_matching_string_format' => ['hello']
68  ];
69  }
70 }
testDateTimeISOTransformation($originVal, $expectedVal)
DateTimeTransformationDataProvider
Transform date format to DateTimeImmutable Please note:
Tests for DateTimeImmutable and Unix Timetable transformation.