Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] create decoded payload new instance from array #38

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/ServerNotifications/V2DecodedPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function __construct(array $rawData)
}

/**
* Create a new instance from a Json Web Signature
* Creates a new instance from a Json Web Signature
*
* @param JsonWebSignature $jws
*
Expand All @@ -75,6 +75,18 @@ public static function fromJws(JsonWebSignature $jws): self
return new self($jws->getClaims());
}

/**
* Creates a new instance from a list of claims
*
* @param array $claims
*
* @return static
*/
public static function fromArray(array $claims): self
{
return new self($claims);
}

/**
* Convert the object to its array representation.
*
Expand Down
26 changes: 23 additions & 3 deletions tests/Unit/ServerNotifications/V2DecodedPayloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class V2DecodedPayloadTest extends TestCase
/**
* @test
*/
public function v2_decoded_payload(): V2DecodedPayload
public function from_jws(): V2DecodedPayload
{
$claims = [
'notificationType' => V2DecodedPayload::TYPE_TEST,
Expand All @@ -35,7 +35,27 @@ public function v2_decoded_payload(): V2DecodedPayload
}

/**
* @depends v2_decoded_payload
* @test
*/
public function from_array(): void
{
$claims = [
'notificationType' => V2DecodedPayload::TYPE_TEST,
'notificationUUID' => $this->faker->uuid(),
'data' => [],
'version' => '2.0',
'signedDate' => $this->faker->unixTime() * 1000,
];

$sut = V2DecodedPayload::fromArray($claims);

foreach ($claims as $key => $value) {
$this->assertEquals($value, $sut->toArray()[$key]);
}
}

/**
* @depends from_jws
* @test
*/
public function get_type(V2DecodedPayload $sut): void
Expand All @@ -44,7 +64,7 @@ public function get_type(V2DecodedPayload $sut): void
}

/**
* @depends v2_decoded_payload
* @depends from_jws
* @test
*/
public function subtype_is_null_if_type_is_test(V2DecodedPayload $sut): void
Expand Down