Skip to content

Commit fe74a1e

Browse files
committed
Merge branch 'develop'
2 parents 6563d2d + 8a87e73 commit fe74a1e

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

.github/workflows/phpunit.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
php-versions: [ "7.1", "7.4", "8.0" ]
12-
phpunit-versions: [ "7", "9" ]
13-
exclude:
14-
- php-versions: "7.1"
15-
phpunit-versions: "9"
16-
- php-versions: "7.4"
17-
phpunit-versions: "7"
18-
- php-versions: "8.0"
19-
phpunit-versions: "7"
11+
php-versions: [ "7.4", "8.0" ]
12+
phpunit-versions: [ "9" ]
2013
steps:
2114
- uses: actions/checkout@v2
2215
- uses: php-actions/composer@v6

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based now on [Keep a
55
Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to
66
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [3.2.3]
9+
### Added another input date format
10+
- Added a `Y-m-d\TH:i:s\Z` input date format additionally to the `Y-m-d\TH:i:s.u\Z`.
11+
812
## [3.2.2]
913
### Fix for an issue with the file list pagination
1014
- Added `getPageRequestParameters` method: use it to load the next page parameters from `$fileListResponse->getNext()`/`$fileListResponse->getPrevious()`.

src/File/AbstractCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ abstract class AbstractCollection implements CollectionInterface
2121
/**
2222
* @return \Traversable
2323
*/
24+
#[\ReturnTypeWillChange]
2425
public function getIterator(): iterable
2526
{
2627
if (\count($this->elements) === 0) {
@@ -35,6 +36,7 @@ public function offsetExists($offset): bool
3536
return isset($this->elements[$offset]) || \array_key_exists($offset, $this->elements);
3637
}
3738

39+
#[\ReturnTypeWillChange]
3840
public function offsetGet($offset)
3941
{
4042
return $this->get($offset);

src/Serializer/Serializer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Serializer implements SerializerInterface
1616
public const JSON_OPTIONS_KEY = 'json_options';
1717
public const EXCLUDE_PROPERTY_KEY = 'exclude_property';
1818
public const DATE_FORMAT = 'Y-m-d\TH:i:s.u\Z';
19+
public const DATE_FORMAT_SHORT = 'Y-m-d\TH:i:s\Z';
1920
public const ORIGINAL_DATE_FORMAT = 'Y-m-d\TH:i:s';
2021

2122
protected static $coreTypes = [
@@ -287,6 +288,9 @@ private function denormalizeDate(string $dateTime): \DateTimeInterface
287288
@\trigger_error('You should set your date.timezone in php.ini', E_USER_WARNING);
288289
}
289290
$date = \date_create_from_format(self::DATE_FORMAT, $dateTime);
291+
if ($date === false) {
292+
$date = \date_create_from_format(self::DATE_FORMAT_SHORT, $dateTime);
293+
}
290294
if ($date === false) {
291295
$date = \date_create_from_format(self::ORIGINAL_DATE_FORMAT, $dateTime);
292296
}

tests/Serializer/DeserializerTest.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function getSerializer()
3838
*
3939
* @return string JSON with image_info data
4040
*/
41-
protected function getImageInfoJson(array $additionalData = [])
41+
protected function getImageInfoJson(array $additionalData = []): string
4242
{
4343
$data = \json_decode(\file_get_contents(\dirname(__DIR__) . '/_data/file-info.json'), true);
4444
$imageInfo = $data['image_info'];
@@ -49,7 +49,7 @@ protected function getImageInfoJson(array $additionalData = [])
4949
return \json_encode($imageInfo);
5050
}
5151

52-
public function testDenormalizeImageInfo()
52+
public function testDenormalizeImageInfo(): void
5353
{
5454
$serializer = $this->getSerializer();
5555

@@ -83,20 +83,44 @@ public function testDenormalizeImageInfo()
8383
self::assertEquals([144, 144], $object->getDpi());
8484
}
8585

86-
public function testNotSerializableClass()
86+
public function testNotSerializableClass(): void
8787
{
8888
$this->expectException(SerializerException::class);
89-
90-
$message = \sprintf('Class \'%s\' must implements the \'%s\' interface', \DateTimeInterface::class, SerializableInterface::class);
9189
$this->getSerializer()->deserialize(\json_encode(\date_create()), \DateTime::class);
92-
$this->expectExceptionMessageRegExp($message);
9390
}
9491

95-
public function testUnableToDecode()
92+
public function testUnableToDecode(): void
9693
{
9794
$this->expectException(ConversionException::class);
98-
9995
$this->getSerializer()->deserialize(\date_create()->format(DATE_ATOM));
100-
$this->expectExceptionMessageRegExp('Unable to decode given value. Error');
96+
}
97+
98+
public function provideDateInDifferentFormats(): array
99+
{
100+
return [
101+
'Y-m-d\TH:i:s.u\Z' => ['2018-11-26T12:49:09.945335Z', null],
102+
'Y-m-d\TH:i:s\Z' => ['2018-11-26T12:49:09Z', null],
103+
'Y-m-d\TH:i:s' => ['2018-11-26T12:49:09', null],
104+
'Invalid' => ['26.11.2021', ConversionException::class],
105+
];
106+
}
107+
108+
/**
109+
* @dataProvider provideDateInDifferentFormats
110+
*/
111+
public function testVariousDateFormats(string $date, string $exception = null): void
112+
{
113+
$serializer = $this->getSerializer();
114+
$denormalizeDate = (new \ReflectionObject($serializer))->getMethod('denormalizeDate');
115+
$denormalizeDate->setAccessible(true);
116+
117+
if ($exception !== null) {
118+
$this->expectException($exception);
119+
}
120+
121+
$result = $denormalizeDate->invokeArgs($serializer, [$date]);
122+
if ($exception === null) {
123+
self::assertInstanceOf(\DateTimeInterface::class, $result);
124+
}
101125
}
102126
}

0 commit comments

Comments
 (0)