SignatureTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /**
  9. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  10. * @since 0.1.0
  11. */
  12. class SignatureTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @var Signer|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $signer;
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function setUp()
  22. {
  23. $this->signer = $this->getMock(Signer::class);
  24. }
  25. /**
  26. * @test
  27. *
  28. * @covers Lcobucci\JWT\Signature::__construct
  29. */
  30. public function constructorMustConfigureAttributes()
  31. {
  32. $signature = new Signature('test');
  33. $this->assertAttributeEquals('test', 'hash', $signature);
  34. }
  35. /**
  36. * @test
  37. *
  38. * @uses Lcobucci\JWT\Signature::__construct
  39. *
  40. * @covers Lcobucci\JWT\Signature::__toString
  41. */
  42. public function toStringMustReturnTheHash()
  43. {
  44. $signature = new Signature('test');
  45. $this->assertEquals('test', (string) $signature);
  46. }
  47. /**
  48. * @test
  49. *
  50. * @uses Lcobucci\JWT\Signature::__construct
  51. * @uses Lcobucci\JWT\Signature::__toString
  52. *
  53. * @covers Lcobucci\JWT\Signature::verify
  54. */
  55. public function verifyMustReturnWhatSignerSays()
  56. {
  57. $this->signer->expects($this->any())
  58. ->method('verify')
  59. ->willReturn(true);
  60. $signature = new Signature('test');
  61. $this->assertTrue($signature->verify($this->signer, 'one', 'key'));
  62. }
  63. }