sign() public method

public sign ( Token $token )
$token Emarref\Jwt\Token
示例#1
0
文件: JwsTest.php 项目: emarref/jwt
 public function testSign()
 {
     $expectedSignature = 'foobar';
     // Configure payload
     $headerParameters = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $headerParameters->expects($this->once())->method('jsonSerialize');
     $this->encoder->expects($this->at(0))->method('encode');
     $header = $this->getMockBuilder('Emarref\\Jwt\\Token\\Header')->getMock();
     $header->expects($this->once())->method('getParameters')->will($this->returnValue($headerParameters));
     // Configure payload
     $claims = $this->getMockBuilder('Emarref\\Jwt\\Token\\PropertyList')->getMock();
     $claims->expects($this->once())->method('jsonSerialize');
     $payload = $this->getMockBuilder('Emarref\\Jwt\\Token\\Payload')->getMock();
     $payload->expects($this->once())->method('getClaims')->will($this->returnValue($claims));
     $this->encoder->expects($this->at(1))->method('encode');
     // Configure token
     $token = $this->getMockBuilder('Emarref\\Jwt\\Token')->getMock();
     $token->expects($this->once())->method('getHeader')->will($this->returnValue($header));
     $token->expects($this->once())->method('getPayload')->will($this->returnValue($payload));
     $this->encryption->expects($this->once())->method('getAlgorithmName')->will($this->returnValue('alg'));
     $this->encryption->expects($this->once())->method('encrypt')->will($this->returnValue($expectedSignature));
     $token->expects($this->once())->method('addHeader')->with(new Algorithm('alg'));
     $token->expects($this->once())->method('setSignature')->with($expectedSignature);
     $this->signer->sign($token);
 }
示例#2
0
文件: Jwt.php 项目: emarref/jwt
 /**
  * @param Token                          $token
  * @param Encryption\EncryptionInterface $encryption
  */
 public function sign(Token $token, Encryption\EncryptionInterface $encryption)
 {
     $signer = new Signature\Jws($encryption, $this->encoder);
     $signer->sign($token);
 }