KeyTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Signer;
  8. use org\bovigo\vfs\vfsStream;
  9. /**
  10. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  11. * @since 3.0.4
  12. */
  13. class KeyTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @before
  17. */
  18. public function configureRootDir()
  19. {
  20. vfsStream::setup(
  21. 'root',
  22. null,
  23. ['test.pem' => 'testing']
  24. );
  25. }
  26. /**
  27. * @test
  28. *
  29. * @covers Lcobucci\JWT\Signer\Key::__construct
  30. * @covers Lcobucci\JWT\Signer\Key::setContent
  31. */
  32. public function constructShouldConfigureContentAndPassphrase()
  33. {
  34. $key = new Key('testing', 'test');
  35. $this->assertAttributeEquals('testing', 'content', $key);
  36. $this->assertAttributeEquals('test', 'passphrase', $key);
  37. }
  38. /**
  39. * @test
  40. *
  41. * @covers Lcobucci\JWT\Signer\Key::__construct
  42. * @covers Lcobucci\JWT\Signer\Key::setContent
  43. * @covers Lcobucci\JWT\Signer\Key::readFile
  44. */
  45. public function constructShouldBeAbleToConfigureContentFromFile()
  46. {
  47. $key = new Key('file://' . vfsStream::url('root/test.pem'));
  48. $this->assertAttributeEquals('testing', 'content', $key);
  49. $this->assertAttributeEquals(null, 'passphrase', $key);
  50. }
  51. /**
  52. * @test
  53. *
  54. * @expectedException \InvalidArgumentException
  55. *
  56. * @covers Lcobucci\JWT\Signer\Key::__construct
  57. * @covers Lcobucci\JWT\Signer\Key::setContent
  58. * @covers Lcobucci\JWT\Signer\Key::readFile
  59. */
  60. public function constructShouldRaiseExceptionWhenFileDoesNotExists()
  61. {
  62. new Key('file://' . vfsStream::url('root/test2.pem'));
  63. }
  64. /**
  65. * @test
  66. *
  67. * @uses Lcobucci\JWT\Signer\Key::__construct
  68. * @uses Lcobucci\JWT\Signer\Key::setContent
  69. *
  70. * @covers Lcobucci\JWT\Signer\Key::getContent
  71. */
  72. public function getContentShouldReturnConfiguredData()
  73. {
  74. $key = new Key('testing', 'test');
  75. $this->assertEquals('testing', $key->getContent());
  76. }
  77. /**
  78. * @test
  79. *
  80. * @uses Lcobucci\JWT\Signer\Key::__construct
  81. * @uses Lcobucci\JWT\Signer\Key::setContent
  82. *
  83. * @covers Lcobucci\JWT\Signer\Key::getPassphrase
  84. */
  85. public function getPassphraseShouldReturnConfiguredData()
  86. {
  87. $key = new Key('testing', 'test');
  88. $this->assertEquals('test', $key->getPassphrase());
  89. }
  90. }