From 0542295ec687a4cf867a3c96ddaa69216fb085f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 27 Nov 2020 02:12:06 +0100 Subject: [PATCH] Apply type guards also on old `Builder#set()` --- src/Builder.php | 2 +- test/unit/BuilderTest.php | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Builder.php b/src/Builder.php index 6a5e9dc0..9f0a5bd9 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -451,7 +451,7 @@ private function forwardCallToCorrectClaimMethod($name, $value) */ public function set($name, $value) { - return $this->configureClaim($name, $value); + return $this->forwardCallToCorrectClaimMethod($name, $value); } /** diff --git a/test/unit/BuilderTest.php b/test/unit/BuilderTest.php index e6d98a86..54789634 100644 --- a/test/unit/BuilderTest.php +++ b/test/unit/BuilderTest.php @@ -604,6 +604,46 @@ public function withClaimShouldSendDeprecationNoticeWhenTryingToConfigureARegist self::assertEquals($expected, $token->claims()->get($name)); } + + /** + * @test + * + * @param string $name + * @param mixed $value + * @param mixed $expected + * @param null|string $otherMessage + * + * @covers ::__construct + * @covers ::set + * @covers ::canOnlyBeUsedAfter + * @covers ::configureClaim + * @covers ::convertItems + * @covers ::convertToDate + * @covers ::getToken + * @covers ::setRegisteredClaim + * @covers ::createSignature + * @covers ::expiresAt + * @covers ::issuedBy + * @covers ::identifiedBy + * @covers ::permittedFor + * @covers ::forwardCallToCorrectClaimMethod + * @covers ::issuedAt + * + * @dataProvider dataWithClaimDeprecationNotice + */ + public function setShouldSendDeprecationNoticeWhenTryingToConfigureARegisteredClaim($name, $value, $expected, $otherMessage = null) + { + if ($otherMessage) { + $this->expectDeprecation($otherMessage); + } + + $token = $this->createBuilder() + ->set($name, $value) + ->getToken(new None(), Key\InMemory::plainText('')); + + self::assertEquals($expected, $token->claims()->get($name)); + } + public function dataWithClaimDeprecationNotice() { $now = time();