BuilderTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. /**
  3. * This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS
  4. *
  5. * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
  6. */
  7. namespace Lcobucci\JWT;
  8. use Lcobucci\JWT\Claim\Factory as ClaimFactory;
  9. use Lcobucci\JWT\Parsing\Encoder;
  10. /**
  11. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  12. * @since 0.1.0
  13. */
  14. class BuilderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @var Encoder|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $encoder;
  20. /**
  21. * @var ClaimFactory|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $claimFactory;
  24. /**
  25. * @var Claim|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $defaultClaim;
  28. /**
  29. * {@inheritdoc}
  30. */
  31. protected function setUp()
  32. {
  33. $this->encoder = $this->getMock(Encoder::class);
  34. $this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false);
  35. $this->defaultClaim = $this->getMock(Claim::class);
  36. $this->claimFactory->expects($this->any())
  37. ->method('create')
  38. ->willReturn($this->defaultClaim);
  39. }
  40. /**
  41. * @return Builder
  42. */
  43. private function createBuilder()
  44. {
  45. return new Builder($this->encoder, $this->claimFactory);
  46. }
  47. /**
  48. * @test
  49. *
  50. * @covers Lcobucci\JWT\Builder::__construct
  51. */
  52. public function constructMustInitializeTheAttributes()
  53. {
  54. $builder = $this->createBuilder();
  55. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  56. $this->assertAttributeEquals([], 'claims', $builder);
  57. $this->assertAttributeEquals(null, 'signature', $builder);
  58. $this->assertAttributeSame($this->encoder, 'encoder', $builder);
  59. $this->assertAttributeSame($this->claimFactory, 'claimFactory', $builder);
  60. }
  61. /**
  62. * @test
  63. *
  64. * @uses Lcobucci\JWT\Builder::__construct
  65. * @uses Lcobucci\JWT\Builder::set
  66. *
  67. * @covers Lcobucci\JWT\Builder::setAudience
  68. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  69. */
  70. public function setAudienceMustChangeTheAudClaim()
  71. {
  72. $builder = $this->createBuilder();
  73. $builder->setAudience('test');
  74. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  75. $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder);
  76. }
  77. /**
  78. * @test
  79. *
  80. * @uses Lcobucci\JWT\Builder::__construct
  81. * @uses Lcobucci\JWT\Builder::set
  82. *
  83. * @covers Lcobucci\JWT\Builder::setAudience
  84. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  85. */
  86. public function setAudienceCanReplicateItemOnHeader()
  87. {
  88. $builder = $this->createBuilder();
  89. $builder->setAudience('test', true);
  90. $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder);
  91. $this->assertAttributeEquals(
  92. ['alg' => 'none', 'typ' => 'JWT', 'aud' => $this->defaultClaim],
  93. 'headers',
  94. $builder
  95. );
  96. }
  97. /**
  98. * @test
  99. *
  100. * @uses Lcobucci\JWT\Builder::__construct
  101. * @uses Lcobucci\JWT\Builder::set
  102. *
  103. * @covers Lcobucci\JWT\Builder::setAudience
  104. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  105. */
  106. public function setAudienceMustKeepAFluentInterface()
  107. {
  108. $builder = $this->createBuilder();
  109. $this->assertSame($builder, $builder->setAudience('test'));
  110. }
  111. /**
  112. * @test
  113. *
  114. * @uses Lcobucci\JWT\Builder::__construct
  115. * @uses Lcobucci\JWT\Builder::set
  116. *
  117. * @covers Lcobucci\JWT\Builder::setExpiration
  118. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  119. */
  120. public function setExpirationMustChangeTheExpClaim()
  121. {
  122. $builder = $this->createBuilder();
  123. $builder->setExpiration('2');
  124. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  125. $this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder);
  126. }
  127. /**
  128. * @test
  129. *
  130. * @uses Lcobucci\JWT\Builder::__construct
  131. * @uses Lcobucci\JWT\Builder::set
  132. *
  133. * @covers Lcobucci\JWT\Builder::setExpiration
  134. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  135. */
  136. public function setExpirationCanReplicateItemOnHeader()
  137. {
  138. $builder = $this->createBuilder();
  139. $builder->setExpiration('2', true);
  140. $this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder);
  141. $this->assertAttributeEquals(
  142. ['alg' => 'none', 'typ' => 'JWT', 'exp' => $this->defaultClaim],
  143. 'headers',
  144. $builder
  145. );
  146. }
  147. /**
  148. * @test
  149. *
  150. * @uses Lcobucci\JWT\Builder::__construct
  151. * @uses Lcobucci\JWT\Builder::set
  152. *
  153. * @covers Lcobucci\JWT\Builder::setExpiration
  154. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  155. */
  156. public function setExpirationMustKeepAFluentInterface()
  157. {
  158. $builder = $this->createBuilder();
  159. $this->assertSame($builder, $builder->setExpiration('2'));
  160. }
  161. /**
  162. * @test
  163. *
  164. * @uses Lcobucci\JWT\Builder::__construct
  165. * @uses Lcobucci\JWT\Builder::set
  166. *
  167. * @covers Lcobucci\JWT\Builder::setId
  168. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  169. */
  170. public function setIdMustChangeTheJtiClaim()
  171. {
  172. $builder = $this->createBuilder();
  173. $builder->setId('2');
  174. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  175. $this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder);
  176. }
  177. /**
  178. * @test
  179. *
  180. * @uses Lcobucci\JWT\Builder::__construct
  181. * @uses Lcobucci\JWT\Builder::set
  182. *
  183. * @covers Lcobucci\JWT\Builder::setId
  184. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  185. */
  186. public function setIdCanReplicateItemOnHeader()
  187. {
  188. $builder = $this->createBuilder();
  189. $builder->setId('2', true);
  190. $this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder);
  191. $this->assertAttributeEquals(
  192. ['alg' => 'none', 'typ' => 'JWT', 'jti' => $this->defaultClaim],
  193. 'headers',
  194. $builder
  195. );
  196. }
  197. /**
  198. * @test
  199. *
  200. * @uses Lcobucci\JWT\Builder::__construct
  201. * @uses Lcobucci\JWT\Builder::set
  202. *
  203. * @covers Lcobucci\JWT\Builder::setId
  204. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  205. */
  206. public function setIdMustKeepAFluentInterface()
  207. {
  208. $builder = $this->createBuilder();
  209. $this->assertSame($builder, $builder->setId('2'));
  210. }
  211. /**
  212. * @test
  213. *
  214. * @uses Lcobucci\JWT\Builder::__construct
  215. * @uses Lcobucci\JWT\Builder::set
  216. *
  217. * @covers Lcobucci\JWT\Builder::setIssuedAt
  218. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  219. */
  220. public function setIssuedAtMustChangeTheIatClaim()
  221. {
  222. $builder = $this->createBuilder();
  223. $builder->setIssuedAt('2');
  224. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  225. $this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder);
  226. }
  227. /**
  228. * @test
  229. *
  230. * @uses Lcobucci\JWT\Builder::__construct
  231. * @uses Lcobucci\JWT\Builder::set
  232. *
  233. * @covers Lcobucci\JWT\Builder::setIssuedAt
  234. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  235. */
  236. public function setIssuedAtCanReplicateItemOnHeader()
  237. {
  238. $builder = $this->createBuilder();
  239. $builder->setIssuedAt('2', true);
  240. $this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder);
  241. $this->assertAttributeEquals(
  242. ['alg' => 'none', 'typ' => 'JWT', 'iat' => $this->defaultClaim],
  243. 'headers',
  244. $builder
  245. );
  246. }
  247. /**
  248. * @test
  249. *
  250. * @uses Lcobucci\JWT\Builder::__construct
  251. * @uses Lcobucci\JWT\Builder::set
  252. *
  253. * @covers Lcobucci\JWT\Builder::setIssuedAt
  254. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  255. */
  256. public function setIssuedAtMustKeepAFluentInterface()
  257. {
  258. $builder = $this->createBuilder();
  259. $this->assertSame($builder, $builder->setIssuedAt('2'));
  260. }
  261. /**
  262. * @test
  263. *
  264. * @uses Lcobucci\JWT\Builder::__construct
  265. * @uses Lcobucci\JWT\Builder::set
  266. *
  267. * @covers Lcobucci\JWT\Builder::setIssuer
  268. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  269. */
  270. public function setIssuerMustChangeTheIssClaim()
  271. {
  272. $builder = $this->createBuilder();
  273. $builder->setIssuer('2');
  274. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  275. $this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder);
  276. }
  277. /**
  278. * @test
  279. *
  280. * @uses Lcobucci\JWT\Builder::__construct
  281. * @uses Lcobucci\JWT\Builder::set
  282. *
  283. * @covers Lcobucci\JWT\Builder::setIssuer
  284. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  285. */
  286. public function setIssuerCanReplicateItemOnHeader()
  287. {
  288. $builder = $this->createBuilder();
  289. $builder->setIssuer('2', true);
  290. $this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder);
  291. $this->assertAttributeEquals(
  292. ['alg' => 'none', 'typ' => 'JWT', 'iss' => $this->defaultClaim],
  293. 'headers',
  294. $builder
  295. );
  296. }
  297. /**
  298. * @test
  299. *
  300. * @uses Lcobucci\JWT\Builder::__construct
  301. * @uses Lcobucci\JWT\Builder::set
  302. *
  303. * @covers Lcobucci\JWT\Builder::setIssuer
  304. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  305. */
  306. public function setIssuerMustKeepAFluentInterface()
  307. {
  308. $builder = $this->createBuilder();
  309. $this->assertSame($builder, $builder->setIssuer('2'));
  310. }
  311. /**
  312. * @test
  313. *
  314. * @uses Lcobucci\JWT\Builder::__construct
  315. * @uses Lcobucci\JWT\Builder::set
  316. *
  317. * @covers Lcobucci\JWT\Builder::setNotBefore
  318. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  319. */
  320. public function setNotBeforeMustChangeTheNbfClaim()
  321. {
  322. $builder = $this->createBuilder();
  323. $builder->setNotBefore('2');
  324. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  325. $this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder);
  326. }
  327. /**
  328. * @test
  329. *
  330. * @uses Lcobucci\JWT\Builder::__construct
  331. * @uses Lcobucci\JWT\Builder::set
  332. *
  333. * @covers Lcobucci\JWT\Builder::setNotBefore
  334. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  335. */
  336. public function setNotBeforeCanReplicateItemOnHeader()
  337. {
  338. $builder = $this->createBuilder();
  339. $builder->setNotBefore('2', true);
  340. $this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder);
  341. $this->assertAttributeEquals(
  342. ['alg' => 'none', 'typ' => 'JWT', 'nbf' => $this->defaultClaim],
  343. 'headers',
  344. $builder
  345. );
  346. }
  347. /**
  348. * @test
  349. *
  350. * @uses Lcobucci\JWT\Builder::__construct
  351. * @uses Lcobucci\JWT\Builder::set
  352. *
  353. * @covers Lcobucci\JWT\Builder::setNotBefore
  354. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  355. */
  356. public function setNotBeforeMustKeepAFluentInterface()
  357. {
  358. $builder = $this->createBuilder();
  359. $this->assertSame($builder, $builder->setNotBefore('2'));
  360. }
  361. /**
  362. * @test
  363. *
  364. * @uses Lcobucci\JWT\Builder::__construct
  365. * @uses Lcobucci\JWT\Builder::set
  366. *
  367. * @covers Lcobucci\JWT\Builder::setSubject
  368. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  369. */
  370. public function setSubjectMustChangeTheSubClaim()
  371. {
  372. $builder = $this->createBuilder();
  373. $builder->setSubject('2');
  374. $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
  375. $this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder);
  376. }
  377. /**
  378. * @test
  379. *
  380. * @uses Lcobucci\JWT\Builder::__construct
  381. * @uses Lcobucci\JWT\Builder::set
  382. *
  383. * @covers Lcobucci\JWT\Builder::setSubject
  384. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  385. */
  386. public function setSubjectCanReplicateItemOnHeader()
  387. {
  388. $builder = $this->createBuilder();
  389. $builder->setSubject('2', true);
  390. $this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder);
  391. $this->assertAttributeEquals(
  392. ['alg' => 'none', 'typ' => 'JWT', 'sub' => $this->defaultClaim],
  393. 'headers',
  394. $builder
  395. );
  396. }
  397. /**
  398. * @test
  399. *
  400. * @uses Lcobucci\JWT\Builder::__construct
  401. * @uses Lcobucci\JWT\Builder::set
  402. *
  403. * @covers Lcobucci\JWT\Builder::setSubject
  404. * @covers Lcobucci\JWT\Builder::setRegisteredClaim
  405. */
  406. public function setSubjectMustKeepAFluentInterface()
  407. {
  408. $builder = $this->createBuilder();
  409. $this->assertSame($builder, $builder->setSubject('2'));
  410. }
  411. /**
  412. * @test
  413. *
  414. * @uses Lcobucci\JWT\Builder::__construct
  415. *
  416. * @covers Lcobucci\JWT\Builder::set
  417. */
  418. public function setMustConfigureTheGivenClaim()
  419. {
  420. $builder = $this->createBuilder();
  421. $builder->set('userId', 2);
  422. $this->assertAttributeEquals(['userId' => $this->defaultClaim], 'claims', $builder);
  423. }
  424. /**
  425. * @test
  426. *
  427. * @uses Lcobucci\JWT\Builder::__construct
  428. *
  429. * @covers Lcobucci\JWT\Builder::set
  430. */
  431. public function setMustKeepAFluentInterface()
  432. {
  433. $builder = $this->createBuilder();
  434. $this->assertSame($builder, $builder->set('userId', 2));
  435. }
  436. /**
  437. * @test
  438. *
  439. * @uses Lcobucci\JWT\Builder::__construct
  440. *
  441. * @covers Lcobucci\JWT\Builder::setHeader
  442. */
  443. public function setHeaderMustConfigureTheGivenClaim()
  444. {
  445. $builder = $this->createBuilder();
  446. $builder->setHeader('userId', 2);
  447. $this->assertAttributeEquals(
  448. ['alg' => 'none', 'typ' => 'JWT', 'userId' => $this->defaultClaim],
  449. 'headers',
  450. $builder
  451. );
  452. }
  453. /**
  454. * @test
  455. *
  456. * @uses Lcobucci\JWT\Builder::__construct
  457. *
  458. * @covers Lcobucci\JWT\Builder::setHeader
  459. */
  460. public function setHeaderMustKeepAFluentInterface()
  461. {
  462. $builder = $this->createBuilder();
  463. $this->assertSame($builder, $builder->setHeader('userId', 2));
  464. }
  465. /**
  466. * @test
  467. *
  468. * @uses Lcobucci\JWT\Builder::__construct
  469. * @uses Lcobucci\JWT\Builder::getToken
  470. * @uses Lcobucci\JWT\Token
  471. *
  472. * @covers Lcobucci\JWT\Builder::sign
  473. */
  474. public function signMustChangeTheSignature()
  475. {
  476. $signer = $this->getMock(Signer::class);
  477. $signature = $this->getMock(Signature::class, [], [], '', false);
  478. $signer->expects($this->any())
  479. ->method('sign')
  480. ->willReturn($signature);
  481. $builder = $this->createBuilder();
  482. $builder->sign($signer, 'test');
  483. $this->assertAttributeSame($signature, 'signature', $builder);
  484. }
  485. /**
  486. * @test
  487. *
  488. * @uses Lcobucci\JWT\Builder::__construct
  489. * @uses Lcobucci\JWT\Builder::getToken
  490. * @uses Lcobucci\JWT\Token
  491. *
  492. * @covers Lcobucci\JWT\Builder::sign
  493. */
  494. public function signMustKeepAFluentInterface()
  495. {
  496. $signer = $this->getMock(Signer::class);
  497. $signature = $this->getMock(Signature::class, [], [], '', false);
  498. $signer->expects($this->any())
  499. ->method('sign')
  500. ->willReturn($signature);
  501. $builder = $this->createBuilder();
  502. $this->assertSame($builder, $builder->sign($signer, 'test'));
  503. return $builder;
  504. }
  505. /**
  506. * @test
  507. *
  508. * @depends signMustKeepAFluentInterface
  509. *
  510. * @covers Lcobucci\JWT\Builder::unsign
  511. */
  512. public function unsignMustRemoveTheSignature(Builder $builder)
  513. {
  514. $builder->unsign();
  515. $this->assertAttributeSame(null, 'signature', $builder);
  516. }
  517. /**
  518. * @test
  519. *
  520. * @depends signMustKeepAFluentInterface
  521. *
  522. * @covers Lcobucci\JWT\Builder::unsign
  523. */
  524. public function unsignMustKeepAFluentInterface(Builder $builder)
  525. {
  526. $this->assertSame($builder, $builder->unsign());
  527. }
  528. /**
  529. * @test
  530. *
  531. * @uses Lcobucci\JWT\Builder::__construct
  532. * @uses Lcobucci\JWT\Builder::sign
  533. * @uses Lcobucci\JWT\Builder::getToken
  534. * @uses Lcobucci\JWT\Token
  535. *
  536. * @covers Lcobucci\JWT\Builder::set
  537. *
  538. * @expectedException BadMethodCallException
  539. */
  540. public function setMustRaiseExceptionWhenTokenHasBeenSigned()
  541. {
  542. $signer = $this->getMock(Signer::class);
  543. $signature = $this->getMock(Signature::class, [], [], '', false);
  544. $signer->expects($this->any())
  545. ->method('sign')
  546. ->willReturn($signature);
  547. $builder = $this->createBuilder();
  548. $builder->sign($signer, 'test');
  549. $builder->set('test', 123);
  550. }
  551. /**
  552. * @test
  553. *
  554. * @uses Lcobucci\JWT\Builder::__construct
  555. * @uses Lcobucci\JWT\Builder::sign
  556. * @uses Lcobucci\JWT\Builder::getToken
  557. * @uses Lcobucci\JWT\Token
  558. *
  559. * @covers Lcobucci\JWT\Builder::setHeader
  560. *
  561. * @expectedException BadMethodCallException
  562. */
  563. public function setHeaderMustRaiseExceptionWhenTokenHasBeenSigned()
  564. {
  565. $signer = $this->getMock(Signer::class);
  566. $signature = $this->getMock(Signature::class, [], [], '', false);
  567. $signer->expects($this->any())
  568. ->method('sign')
  569. ->willReturn($signature);
  570. $builder = $this->createBuilder();
  571. $builder->sign($signer, 'test');
  572. $builder->setHeader('test', 123);
  573. }
  574. /**
  575. * @test
  576. *
  577. * @uses Lcobucci\JWT\Builder::__construct
  578. * @uses Lcobucci\JWT\Builder::set
  579. * @uses Lcobucci\JWT\Token
  580. *
  581. * @covers Lcobucci\JWT\Builder::getToken
  582. */
  583. public function getTokenMustReturnANewTokenWithCurrentConfiguration()
  584. {
  585. $signature = $this->getMock(Signature::class, [], [], '', false);
  586. $this->encoder->expects($this->exactly(2))
  587. ->method('jsonEncode')
  588. ->withConsecutive([['typ'=> 'JWT', 'alg' => 'none']], [['test' => $this->defaultClaim]])
  589. ->willReturnOnConsecutiveCalls('1', '2');
  590. $this->encoder->expects($this->exactly(3))
  591. ->method('base64UrlEncode')
  592. ->withConsecutive(['1'], ['2'], [$signature])
  593. ->willReturnOnConsecutiveCalls('1', '2', '3');
  594. $builder = $this->createBuilder()->set('test', 123);
  595. $builderSign = new \ReflectionProperty($builder, 'signature');
  596. $builderSign->setAccessible(true);
  597. $builderSign->setValue($builder, $signature);
  598. $token = $builder->getToken();
  599. $tokenSign = new \ReflectionProperty($token, 'signature');
  600. $tokenSign->setAccessible(true);
  601. $this->assertAttributeEquals(['1', '2', '3'], 'payload', $token);
  602. $this->assertAttributeEquals($token->getHeaders(), 'headers', $builder);
  603. $this->assertAttributeEquals($token->getClaims(), 'claims', $builder);
  604. $this->assertAttributeSame($tokenSign->getValue($token), 'signature', $builder);
  605. }
  606. }