/** * 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()); }
/** * Returns the value of a constant. * * @return mixed The value of the constant. * @throws ClassConstantNotFoundException if the constant is a class constant and if this class cannot be found. * @throws UndefinedConstantExceptions if the constant isn't defined. */ private function getConstant() { /* @var \com\mohiva\common\lang\AnnotationToken $token */ if ($this->stream->isNext(AnnotationLexer::T_NS_SEPARATOR)) { $token = $this->next(AnnotationLexer::T_NS_SEPARATOR); $constant = $token->getValue(); } else { $constant = ''; } $token = $this->next(AnnotationLexer::T_NAME); $constant .= $token->getValue(); while ($this->stream->isNext(AnnotationLexer::T_NS_SEPARATOR)) { $token = $this->next(AnnotationLexer::T_NS_SEPARATOR); $constant .= $token->getValue(); $token = $this->next(AnnotationLexer::T_NAME); $constant .= $token->getValue(); } // Get a class constant $colon = $this->stream->isNext(AnnotationLexer::T_DOUBLE_COLON); if ($colon && $constant == 'self') { $constant = $this->context->getClass(); $token = $this->next(AnnotationLexer::T_DOUBLE_COLON); $constant .= $token->getValue(); $token = $this->next(AnnotationLexer::T_NAME); $constant .= $token->getValue(); } else { if ($colon) { $constant = $this->getFullyQualifiedName($constant); $token = $this->next(AnnotationLexer::T_DOUBLE_COLON); $constant .= $token->getValue(); $token = $this->next(AnnotationLexer::T_NAME); $constant .= $token->getValue(); } } try { return constant($constant); } catch (ClassNotFoundException $e) { $snippet = preg_replace('/[\\r\\n\\t]*/', '', substr($this->stream->getSource(), $token->getOffset(), 50)); $message = "The class for constant `{$constant}` cannot be found; "; $message .= "called in DocBlock for: {$this->context->getLocation()}; "; $message .= "found at offset `{$token->getOffset()}` near `{$snippet}`"; throw new ClassNotFoundException($message, null, $e); } catch (Exception $e) { $snippet = preg_replace('/[\\r\\n\\t]*/', '', substr($this->stream->getSource(), $token->getOffset(), 20)); $message = "The constant `{$constant}` is not defined; "; $message .= "called in DocBlock for: {$this->context->getLocation()}; "; $message .= "found at offset `{$token->getOffset()}` near `{$snippet}`"; throw new UndefinedConstantException($message, null, $e); } }