public function testCheckSignatureWithInvalidValue()
 {
     $this->signatureGenerator->expects($this->any())->method('generateSignatureKey')->with(array('foo' => 'bar'))->will($this->returnValue('Example'));
     $this->signatureGenerator->expects($this->any())->method('generateSignature')->with(array('foo' => 'bar'))->will($this->returnValue('invalid-signature'));
     $this->setExpectedException('ProxyManager\\Signature\\Exception\\InvalidSignatureException');
     $this->signatureChecker->checkSignature(new ReflectionClass($this), array('foo' => 'bar'));
 }
 public function testAddSignature()
 {
     /* @var $classGenerator \PHPUnit_Framework_MockObject_MockObject|\Zend\Code\Generator\ClassGenerator */
     $classGenerator = $this->getMock('Zend\\Code\\Generator\\ClassGenerator');
     $classGenerator->expects($this->once())->method('addPropertyFromGenerator')->with($this->callback(function (PropertyGenerator $property) {
         return $property->getName() === 'signaturePropertyName' && $property->isStatic() && $property->getVisibility() === 'private' && $property->getDefaultValue()->getValue() === 'valid-signature';
     }));
     $this->signatureGenerator->expects($this->any())->method('generateSignature')->with(array('foo' => 'bar'))->will($this->returnValue('valid-signature'));
     $this->signatureGenerator->expects($this->any())->method('generateSignatureKey')->with(array('foo' => 'bar'))->will($this->returnValue('PropertyName'));
     $this->classSignatureGenerator->addSignature($classGenerator, array('foo' => 'bar'));
 }
 /**
  * {@inheritDoc}
  */
 public function checkSignature(ReflectionClass $class, array $parameters)
 {
     $propertyName = 'signature' . $this->signatureGenerator->generateSignatureKey($parameters);
     $signature = $this->signatureGenerator->generateSignature($parameters);
     $defaultProperties = $class->getDefaultProperties();
     if (!isset($defaultProperties[$propertyName])) {
         throw MissingSignatureException::fromMissingSignature($class, $parameters, $signature);
     }
     if ($defaultProperties[$propertyName] !== $signature) {
         throw InvalidSignatureException::fromInvalidSignature($class, $parameters, $defaultProperties[$propertyName], $signature);
     }
 }
 /**
  * {@inheritDoc}
  *
  * @throws \Zend\Code\Exception\InvalidArgumentException
  */
 public function addSignature(ClassGenerator $classGenerator, array $parameters) : ClassGenerator
 {
     $classGenerator->addPropertyFromGenerator(new PropertyGenerator('signature' . $this->signatureGenerator->generateSignatureKey($parameters), $this->signatureGenerator->generateSignature($parameters), PropertyGenerator::FLAG_STATIC | PropertyGenerator::FLAG_PRIVATE));
     return $classGenerator;
 }