EncoderTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Parsing;
  8. /**
  9. * @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
  10. * @since 0.1.0
  11. */
  12. class EncoderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @test
  16. *
  17. * @covers Lcobucci\JWT\Parsing\Encoder::jsonEncode
  18. */
  19. public function jsonEncodeMustReturnAJSONString()
  20. {
  21. $encoder = new Encoder();
  22. $this->assertEquals('{"test":"test"}', $encoder->jsonEncode(['test' => 'test']));
  23. }
  24. /**
  25. * @test
  26. *
  27. * @covers Lcobucci\JWT\Parsing\Encoder::jsonEncode
  28. *
  29. * @expectedException \RuntimeException
  30. */
  31. public function jsonEncodeMustRaiseExceptionWhenAnErrorHasOccured()
  32. {
  33. $encoder = new Encoder();
  34. $encoder->jsonEncode("\xB1\x31");
  35. }
  36. /**
  37. * @test
  38. *
  39. * @covers Lcobucci\JWT\Parsing\Encoder::base64UrlEncode
  40. */
  41. public function base64UrlEncodeMustReturnAnUrlSafeBase64()
  42. {
  43. $data = base64_decode('0MB2wKB+L3yvIdzeggmJ+5WOSLaRLTUPXbpzqUe0yuo=');
  44. $encoder = new Encoder();
  45. $this->assertEquals('0MB2wKB-L3yvIdzeggmJ-5WOSLaRLTUPXbpzqUe0yuo', $encoder->base64UrlEncode($data));
  46. }
  47. }