Skip to content

Commit

Permalink
SDK-1412: Format expiry date with milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston committed Jun 17, 2020
1 parent e1fc8ef commit 1e0d7c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty;

use Yoti\Util\DateTime;
use Yoti\Util\Validation;

class SandboxIssuingAttributes implements \JsonSerializable
Expand Down Expand Up @@ -37,7 +36,9 @@ public function __construct(\DateTime $expiryDate, array $definitions)
public function jsonSerialize(): \stdClass
{
return (object) [
'expiry_date' => $this->expiryDate->format(DateTime::RFC3339),
'expiry_date' => $this->expiryDate
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339_EXTENDED),
'definitions' => $this->definitions,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function shouldBuildSandboxAttributeIssuanceDetails()
'value' => [
'issuance_token' => self::SOME_TOKEN,
'issuing_attributes' => [
'expiry_date' => $someDateTime->format(DateTime::RFC3339),
'expiry_date' => $someDateTime->format(\DateTime::RFC3339_EXTENDED),
'definitions' => [
[
'name' => self::SOME_DEFINITION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
*/
class SandboxIssuingAttributesTest extends TestCase
{
private const SOME_DATE_STRING = '2020-01-02T01:02:03.123456Z';

/**
* @test
*
* @covers ::__construct
* @covers ::jsonSerialize
*
* @dataProvider expiryDateDataProvider
*/
public function shouldSerializeToJson()
public function shouldSerializeToJson($inputDate, $outputDate)
{
$definitionMock = $this->createMock(SandboxDefinition::class);
$definitionMock
->method('jsonSerialize')
->willReturn((object) ['some' => 'definition']);

$someDateTime = DateTime::stringToDateTime(self::SOME_DATE_STRING);
$someDateTime = DateTime::stringToDateTime($inputDate);

$sandboxIssuingAttributes = new SandboxIssuingAttributes(
$someDateTime,
Expand All @@ -38,10 +38,22 @@ public function shouldSerializeToJson()

$this->assertJsonStringEqualsJsonString(
json_encode([
'expiry_date' => $someDateTime->format(DateTime::RFC3339),
'expiry_date' => $outputDate,
'definitions' => [$definitionMock],
]),
json_encode($sandboxIssuingAttributes)
);
}

/**
* Provides test expiry dates.
*/
public function expiryDateDataProvider()
{
return [
['2020-01-02T01:02:03.123456Z', '2020-01-02T01:02:03.123+00:00'],
['2020-01-01T01:02:03.123+04:00', '2019-12-31T21:02:03.123+00:00'],
['2020-01-02T01:02:03.123-02:00', '2020-01-02T03:02:03.123+00:00']
];
}
}

0 comments on commit 1e0d7c8

Please sign in to comment.