DecoderTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 DecoderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @test
  16. *
  17. * @covers Lcobucci\JWT\Parsing\Decoder::jsonDecode
  18. */
  19. public function jsonDecodeMustReturnTheDecodedData()
  20. {
  21. $decoder = new Decoder();
  22. $this->assertEquals(
  23. (object) ['test' => 'test'],
  24. $decoder->jsonDecode('{"test":"test"}')
  25. );
  26. }
  27. /**
  28. * @test
  29. *
  30. * @covers Lcobucci\JWT\Parsing\Decoder::jsonDecode
  31. *
  32. * @expectedException \RuntimeException
  33. */
  34. public function jsonDecodeMustRaiseExceptionWhenAnErrorHasOccured()
  35. {
  36. $decoder = new Decoder();
  37. $decoder->jsonDecode('{"test":\'test\'}');
  38. }
  39. /**
  40. * @test
  41. *
  42. * @covers Lcobucci\JWT\Parsing\Decoder::base64UrlDecode
  43. */
  44. public function base64UrlDecodeMustReturnTheRightData()
  45. {
  46. $data = base64_decode('0MB2wKB+L3yvIdzeggmJ+5WOSLaRLTUPXbpzqUe0yuo=');
  47. $decoder = new Decoder();
  48. $this->assertEquals($data, $decoder->base64UrlDecode('0MB2wKB-L3yvIdzeggmJ-5WOSLaRLTUPXbpzqUe0yuo'));
  49. }
  50. }