@@ -564,15 +564,61 @@ public function withClaimMustKeepAFluentInterface()
564
564
/**
565
565
* @test
566
566
*
567
+ * @param string $name
568
+ * @param mixed $value
569
+ * @param mixed $expected
570
+ *
567
571
* @covers ::__construct
568
572
* @covers ::withClaim
569
573
* @covers \Lcobucci\JWT\Token\RegisteredClaimGiven
574
+ *
575
+ * @dataProvider dataWithClaimDeprecationNotice
570
576
*/
571
- public function withClaimShouldThrowExceptionWhenTryingToConfigureARegisteredClaim ()
577
+ public function withClaimShouldSendDeprecationNoticeWhenTryingToConfigureARegisteredClaim ($ name , $ value , $ expected )
578
+ {
579
+ $ key = $ this ->createMock (Key::class);
580
+ $ signature = $ this ->createMock (Signature::class);
581
+ $ signature
582
+ ->expects (static ::once ())
583
+ ->method ('hash ' )
584
+ ->willReturn ('--hash-- ' )
585
+ ;
586
+
587
+ $ signer = $ this ->createMock (Signer::class);
588
+ $ signer
589
+ ->expects (static ::once ())
590
+ ->method ('sign ' )
591
+ ->willReturn ($ signature )
592
+ ;
593
+
594
+
595
+
596
+ $ this ->expectDeprecation ('The use of the method "withClaim" is deprecated for registered claims. Please use dedicated method instead. ' );
597
+
598
+ $ token = $ this
599
+ ->createBuilder ()
600
+ ->withClaim ($ name , $ value )
601
+ ->getToken ($ signer , $ key )
602
+ ;
603
+
604
+ self ::assertEquals ($ expected , $ token ->claims ()->get ($ name ));
605
+ }
606
+
607
+ public function dataWithClaimDeprecationNotice ()
572
608
{
573
- $ this ->expectException (RegisteredClaimGiven::class);
609
+ $ now = time ();
610
+ $ nowAsDate = new DateTimeImmutable ('@ ' . $ now );
611
+ $ nowPlus1HourAsDate = $ nowAsDate ->modify ('+1 hour ' );
574
612
575
- $ this ->createBuilder ()->withClaim ('sub ' , 'me ' );
613
+ return [
614
+ ['sub ' , 'me ' , 'me ' ],
615
+ ['aud ' , 'him ' , ['him ' ]],
616
+ ['jti ' , '0123456789ABCDEF ' , '0123456789ABCDEF ' ],
617
+ ['iss ' , 'you ' , 'you ' ],
618
+ ['exp ' , $ nowPlus1HourAsDate ->getTimestamp (), $ nowPlus1HourAsDate ->getTimestamp ()],
619
+ ['iat ' , $ now , $ nowAsDate ->getTimestamp ()],
620
+ ['nbf ' , $ now , $ nowAsDate ->getTimestamp ()],
621
+ ];
576
622
}
577
623
578
624
/**
0 commit comments