SignatureParametersParserTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace HttpSignatures\tests;
  3. use HttpSignatures\SignatureParametersParser;
  4. class SignatureParametersParserTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testParseReturnsExpectedAssociativeArray()
  7. {
  8. $parser = new SignatureParametersParser(
  9. 'keyId="example",algorithm="hmac-sha1",headers="(request-target) date",signature="b64"'
  10. );
  11. $this->assertEquals(
  12. [
  13. 'keyId' => 'example',
  14. 'algorithm' => 'hmac-sha1',
  15. 'headers' => '(request-target) date',
  16. 'signature' => 'b64',
  17. ],
  18. $parser->parse()
  19. );
  20. }
  21. /**
  22. * @expectedException HttpSignatures\SignatureParseException
  23. */
  24. public function testParseThrowsTypedException()
  25. {
  26. $parser = new SignatureParametersParser('nope');
  27. $parser->parse();
  28. }
  29. /**
  30. * @expectedException HttpSignatures\SignatureParseException
  31. */
  32. public function testParseExceptionForMissingComponents()
  33. {
  34. $parser = new SignatureParametersParser(
  35. 'keyId="example",algorithm="hmac-sha1",headers="(request-target) date"'
  36. );
  37. $parser->parse();
  38. }
  39. }