/**
  * Test all getters for the values set with the constructor.
  */
 public function testConstructorAccessors()
 {
     $namespace = sha1(microtime(true));
     $useStatements = array(sha1(microtime(true)));
     $class = sha1(microtime(true));
     $location = sha1(microtime(true));
     $context = new AnnotationContext($namespace, $useStatements, $class, $location);
     $this->assertSame($namespace, $context->getNamespace());
     $this->assertSame($useStatements, $context->getUseStatements());
     $this->assertSame($class, $context->getClass());
     $this->assertSame($location, $context->getLocation());
 }
Beispiel #2
0
 /**
  * Throw a syntax error exception.
  *
  * @param array $tokens A list with expected tokens.
  * @param AnnotationToken $lookahead The lookahead token.
  * @throws SyntaxErrorException if a syntax error occurs.
  */
 private function syntaxError(array $tokens, AnnotationToken $lookahead = null)
 {
     $refObject = new ReflectionClass(__NAMESPACE__ . '\\AnnotationLexer');
     $tokens = array_map(array($refObject, 'getConstantByValue'), $tokens);
     $tokens = implode('`,`', $tokens);
     if (!$lookahead) {
         $message = "Syntax error in DocBlock for: {$this->context->getLocation()}, ";
         $message .= "expected tokens: `{$tokens}` but end of string reached";
     } else {
         $snippet = preg_replace('/[\\r\\n\\t]*/', '', substr($this->stream->getSource(), $lookahead->getOffset(), 50));
         $message = "Syntax error in DocBlock for: {$this->context->getLocation()}, ";
         $message .= "expected tokens: `{$tokens}` but found `{$lookahead->getValue()}` ";
         $message .= "at offset `{$lookahead->getOffset()}` near: `{$snippet}`";
     }
     throw new SyntaxErrorException($message);
 }