Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rsedykh committed Apr 4, 2022
2 parents 6563d2d + 8a87e73 commit fe74a1e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ jobs:
strategy:
fail-fast: true
matrix:
php-versions: [ "7.1", "7.4", "8.0" ]
phpunit-versions: [ "7", "9" ]
exclude:
- php-versions: "7.1"
phpunit-versions: "9"
- php-versions: "7.4"
phpunit-versions: "7"
- php-versions: "8.0"
phpunit-versions: "7"
php-versions: [ "7.4", "8.0" ]
phpunit-versions: [ "9" ]
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based now on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.2.3]
### Added another input date format
- Added a `Y-m-d\TH:i:s\Z` input date format additionally to the `Y-m-d\TH:i:s.u\Z`.

## [3.2.2]
### Fix for an issue with the file list pagination
- Added `getPageRequestParameters` method: use it to load the next page parameters from `$fileListResponse->getNext()`/`$fileListResponse->getPrevious()`.
Expand Down
2 changes: 2 additions & 0 deletions src/File/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class AbstractCollection implements CollectionInterface
/**
* @return \Traversable
*/
#[\ReturnTypeWillChange]
public function getIterator(): iterable
{
if (\count($this->elements) === 0) {
Expand All @@ -35,6 +36,7 @@ public function offsetExists($offset): bool
return isset($this->elements[$offset]) || \array_key_exists($offset, $this->elements);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
Expand Down
4 changes: 4 additions & 0 deletions src/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Serializer implements SerializerInterface
public const JSON_OPTIONS_KEY = 'json_options';
public const EXCLUDE_PROPERTY_KEY = 'exclude_property';
public const DATE_FORMAT = 'Y-m-d\TH:i:s.u\Z';
public const DATE_FORMAT_SHORT = 'Y-m-d\TH:i:s\Z';
public const ORIGINAL_DATE_FORMAT = 'Y-m-d\TH:i:s';

protected static $coreTypes = [
Expand Down Expand Up @@ -287,6 +288,9 @@ private function denormalizeDate(string $dateTime): \DateTimeInterface
@\trigger_error('You should set your date.timezone in php.ini', E_USER_WARNING);
}
$date = \date_create_from_format(self::DATE_FORMAT, $dateTime);
if ($date === false) {
$date = \date_create_from_format(self::DATE_FORMAT_SHORT, $dateTime);
}
if ($date === false) {
$date = \date_create_from_format(self::ORIGINAL_DATE_FORMAT, $dateTime);
}
Expand Down
42 changes: 33 additions & 9 deletions tests/Serializer/DeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function getSerializer()
*
* @return string JSON with image_info data
*/
protected function getImageInfoJson(array $additionalData = [])
protected function getImageInfoJson(array $additionalData = []): string
{
$data = \json_decode(\file_get_contents(\dirname(__DIR__) . '/_data/file-info.json'), true);
$imageInfo = $data['image_info'];
Expand All @@ -49,7 +49,7 @@ protected function getImageInfoJson(array $additionalData = [])
return \json_encode($imageInfo);
}

public function testDenormalizeImageInfo()
public function testDenormalizeImageInfo(): void
{
$serializer = $this->getSerializer();

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

public function testNotSerializableClass()
public function testNotSerializableClass(): void
{
$this->expectException(SerializerException::class);

$message = \sprintf('Class \'%s\' must implements the \'%s\' interface', \DateTimeInterface::class, SerializableInterface::class);
$this->getSerializer()->deserialize(\json_encode(\date_create()), \DateTime::class);
$this->expectExceptionMessageRegExp($message);
}

public function testUnableToDecode()
public function testUnableToDecode(): void
{
$this->expectException(ConversionException::class);

$this->getSerializer()->deserialize(\date_create()->format(DATE_ATOM));
$this->expectExceptionMessageRegExp('Unable to decode given value. Error');
}

public function provideDateInDifferentFormats(): array
{
return [
'Y-m-d\TH:i:s.u\Z' => ['2018-11-26T12:49:09.945335Z', null],
'Y-m-d\TH:i:s\Z' => ['2018-11-26T12:49:09Z', null],
'Y-m-d\TH:i:s' => ['2018-11-26T12:49:09', null],
'Invalid' => ['26.11.2021', ConversionException::class],
];
}

/**
* @dataProvider provideDateInDifferentFormats
*/
public function testVariousDateFormats(string $date, string $exception = null): void
{
$serializer = $this->getSerializer();
$denormalizeDate = (new \ReflectionObject($serializer))->getMethod('denormalizeDate');
$denormalizeDate->setAccessible(true);

if ($exception !== null) {
$this->expectException($exception);
}

$result = $denormalizeDate->invokeArgs($serializer, [$date]);
if ($exception === null) {
self::assertInstanceOf(\DateTimeInterface::class, $result);
}
}
}

0 comments on commit fe74a1e

Please sign in to comment.