Exemple #1
0
 function it_uses_merged_definition_if_default_definition_exists_to_build_Token(TokenDefinition $defaultDefinition, TokenDefinition $definition, TokenDefinition $mergedDefinition, Token $token, TokenBuilder $builder)
 {
     $type = 'type';
     $defaultDefinition->merge($definition)->willReturn($mergedDefinition);
     $definition->getType()->willReturn($type);
     /**
      * $definition is created based on CLONED version of original, so it is not possible to
      * check if object passed as an argument is exactly the same. It is possible to checks
      * that it is not the usual one ($definition)
      */
     $builder->build(a::not($definition))->willReturn($token);
     $this->beConstructedWith($builder);
     $this->setDefaultDefinition($defaultDefinition)->addDefinition($definition)->build($type);
 }
Exemple #2
0
 /**
  * @param TokenDefinition $definition
  * @return Token
  */
 public function build(TokenDefinition $definition)
 {
     $token = $this->getToken($definition->getClass());
     $token->setType($definition->getType());
     $token->setHash($this->generateHash($definition->getHashAlgorithm()));
     $token->setUsages($definition->getUsages());
     $token->setExpiresAt($this->calculateExpirationDate($definition->getTtl()));
     return $token;
 }
 function it_does_not_merge_token_definition_if_values_were_already_set(TokenDefinition $definition)
 {
     $class = 'My\\Class';
     $hashAlgorithm = 'my_alg';
     $usages = 3;
     $ttl = '3 days';
     $this->setClass($class);
     $this->setHashAlgorithm($hashAlgorithm);
     $this->setUsages($usages);
     $this->setTtl($ttl);
     $definition->getClass()->willReturn('My\\Class2');
     $definition->getHashAlgorithm()->willReturn('test_alg');
     $definition->getUsages()->willReturn(0);
     $definition->getTtl()->willReturn('1 day');
     $token = $this->merge($definition);
     $token->getClass()->shouldReturn($class);
     $token->getHashAlgorithm()->shouldReturn($hashAlgorithm);
     $token->getUsages()->shouldReturn($usages);
     $token->getTtl()->shouldReturn($ttl);
 }
Exemple #4
0
 /**
  * @param TokenDefinition $definition
  * @return TokenDirector
  */
 public function addDefinition(TokenDefinition $definition)
 {
     $this->definitions[$definition->getType()] = $definition;
     return $this;
 }
Exemple #5
0
 function it_throws_an_exception_if_token_class_is_not_an_instance_of_DevhelpTokenToken(TokenDefinition $definition)
 {
     $definition->getClass()->willReturn('\\stdClass');
     $this->shouldThrow('\\InvalidArgumentException')->duringBuild($definition);
 }