@@ -533,6 +533,7 @@ public function relatedToMustKeepAFluentInterface()
533533 * @covers ::configureClaim
534534 * @covers ::createSignature
535535 * @covers ::convertItems
536+ * @covers ::forwardCallToCorrectClaimMethod
536537 *
537538 * @uses \Lcobucci\JWT\Builder::getToken
538539 */
@@ -553,6 +554,7 @@ public function withClaimMustConfigureTheGivenClaim()
553554 * @covers ::__construct
554555 * @covers ::withClaim
555556 * @covers ::configureClaim
557+ * @covers ::forwardCallToCorrectClaimMethod
556558 */
557559 public function withClaimMustKeepAFluentInterface ()
558560 {
@@ -564,15 +566,99 @@ public function withClaimMustKeepAFluentInterface()
564566 /**
565567 * @test
566568 *
569+ * @param string $name
570+ * @param mixed $value
571+ * @param mixed $expected
572+ * @param null|string $otherMessage
573+ *
567574 * @covers ::__construct
568575 * @covers ::withClaim
569- * @covers \Lcobucci\JWT\Token\RegisteredClaimGiven
576+ * @covers ::canOnlyBeUsedAfter
577+ * @covers ::configureClaim
578+ * @covers ::convertItems
579+ * @covers ::convertToDate
580+ * @covers ::getToken
581+ * @covers ::setRegisteredClaim
582+ * @covers ::createSignature
583+ * @covers ::expiresAt
584+ * @covers ::issuedBy
585+ * @covers ::identifiedBy
586+ * @covers ::permittedFor
587+ * @covers ::forwardCallToCorrectClaimMethod
588+ * @covers ::issuedAt
589+ *
590+ * @dataProvider dataWithClaimDeprecationNotice
570591 */
571- public function withClaimShouldThrowExceptionWhenTryingToConfigureARegisteredClaim ()
592+ public function withClaimShouldSendDeprecationNoticeWhenTryingToConfigureARegisteredClaim ($ name , $ value , $ expected , $ otherMessage = null )
593+ {
594+ $ this ->expectDeprecation ('The use of the method "withClaim" is deprecated for registered claims. Please use dedicated method instead. ' );
595+
596+ if ($ otherMessage ) {
597+ $ this ->expectDeprecation ($ otherMessage );
598+ }
599+
600+ $ token = $ this ->createBuilder ()
601+ ->withClaim ($ name , $ value )
602+ ->getToken (new None (), Key \InMemory::plainText ('' ));
603+
604+ self ::assertEquals ($ expected , $ token ->claims ()->get ($ name ));
605+ }
606+
607+
608+ /**
609+ * @test
610+ *
611+ * @param string $name
612+ * @param mixed $value
613+ * @param mixed $expected
614+ * @param null|string $otherMessage
615+ *
616+ * @covers ::__construct
617+ * @covers ::set
618+ * @covers ::canOnlyBeUsedAfter
619+ * @covers ::configureClaim
620+ * @covers ::convertItems
621+ * @covers ::convertToDate
622+ * @covers ::getToken
623+ * @covers ::setRegisteredClaim
624+ * @covers ::createSignature
625+ * @covers ::expiresAt
626+ * @covers ::issuedBy
627+ * @covers ::identifiedBy
628+ * @covers ::permittedFor
629+ * @covers ::forwardCallToCorrectClaimMethod
630+ * @covers ::issuedAt
631+ *
632+ * @dataProvider dataWithClaimDeprecationNotice
633+ */
634+ public function setShouldSendDeprecationNoticeWhenTryingToConfigureARegisteredClaim ($ name , $ value , $ expected , $ otherMessage = null )
635+ {
636+ if ($ otherMessage ) {
637+ $ this ->expectDeprecation ($ otherMessage );
638+ }
639+
640+ $ token = $ this ->createBuilder ()
641+ ->set ($ name , $ value )
642+ ->getToken (new None (), Key \InMemory::plainText ('' ));
643+
644+ self ::assertEquals ($ expected , $ token ->claims ()->get ($ name ));
645+ }
646+
647+ public function dataWithClaimDeprecationNotice ()
572648 {
573- $ this ->expectException (RegisteredClaimGiven::class);
649+ $ now = time ();
650+ $ nowAsDate = new DateTimeImmutable ('@ ' . $ now );
651+ $ nowPlus1HourAsDate = $ nowAsDate ->modify ('+1 hour ' );
574652
575- $ this ->createBuilder ()->withClaim ('sub ' , 'me ' );
653+ return [
654+ ['sub ' , 'me ' , 'me ' ],
655+ ['aud ' , 'him ' , ['him ' ]],
656+ ['jti ' , '0123456789ABCDEF ' , '0123456789ABCDEF ' ],
657+ ['iss ' , 'you ' , 'you ' ],
658+ ['exp ' , $ nowPlus1HourAsDate ->getTimestamp (), $ nowPlus1HourAsDate , 'Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. ' ],
659+ ['iat ' , $ now , $ nowAsDate , 'Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. ' ],
660+ ['nbf ' , $ now , $ nowAsDate , 'Using integers for registered date claims is deprecated, please use DateTimeImmutable objects instead. ' ],
661+ ];
576662 }
577663
578664 /**
@@ -687,6 +773,7 @@ public function unsignMustKeepAFluentInterface(Builder $builder)
687773 * @uses \Lcobucci\JWT\Builder::__construct
688774 * @uses \Lcobucci\JWT\Builder::configureClaim
689775 * @uses \Lcobucci\JWT\Builder::withClaim
776+ * @uses \Lcobucci\JWT\Builder::forwardCallToCorrectClaimMethod
690777 */
691778 public function getTokenMustReturnANewTokenWithCurrentConfiguration ()
692779 {
0 commit comments