diff --git a/src/ServerNotifications/V2DecodedPayload.php b/src/ServerNotifications/V2DecodedPayload.php index 034815f..f028cba 100644 --- a/src/ServerNotifications/V2DecodedPayload.php +++ b/src/ServerNotifications/V2DecodedPayload.php @@ -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 * @@ -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. * diff --git a/tests/Unit/ServerNotifications/V2DecodedPayloadTest.php b/tests/Unit/ServerNotifications/V2DecodedPayloadTest.php index a70afb2..79e0581 100644 --- a/tests/Unit/ServerNotifications/V2DecodedPayloadTest.php +++ b/tests/Unit/ServerNotifications/V2DecodedPayloadTest.php @@ -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, @@ -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 @@ -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