diff --git a/src/Annotation/AnnotationCollection.php b/src/Annotation/AnnotationCollection.php deleted file mode 100644 index 74e2b050..00000000 --- a/src/Annotation/AnnotationCollection.php +++ /dev/null @@ -1,34 +0,0 @@ -setIdentifiers([ - __CLASS__, - get_class($this), - ]); - $this->events = $events; - - return $this; - } - - /** - * Retrieve event manager - * - * Lazy loads an instance if none registered. - * - * @return EventManagerInterface - */ - public function getEventManager() - { - if (null === $this->events) { - $this->setEventManager(new EventManager()); - } - - return $this->events; - } - - /** - * Attach a parser to listen to the createAnnotation event - * - * @param ParserInterface $parser - * @return AnnotationManager - */ - public function attach(ParserInterface $parser) - { - $this->getEventManager() - ->attach(self::EVENT_CREATE_ANNOTATION, [$parser, 'onCreateAnnotation']); - - return $this; - } - - /** - * Create Annotation - * - * @param string[] $annotationData - * @return false|\stdClass - */ - public function createAnnotation(array $annotationData) - { - $event = new Event(); - $event->setName(self::EVENT_CREATE_ANNOTATION); - $event->setTarget($this); - $event->setParams([ - 'class' => $annotationData[0], - 'content' => $annotationData[1], - 'raw' => $annotationData[2], - ]); - - $eventManager = $this->getEventManager(); - $results = $eventManager->triggerEventUntil(function ($r) { - return is_object($r); - }, $event); - - $annotation = $results->last(); - - return is_object($annotation) ? $annotation : false; - } -} diff --git a/src/Annotation/Parser/DoctrineAnnotationParser.php b/src/Annotation/Parser/DoctrineAnnotationParser.php deleted file mode 100644 index 64f7ffa5..00000000 --- a/src/Annotation/Parser/DoctrineAnnotationParser.php +++ /dev/null @@ -1,162 +0,0 @@ -docParser = $docParser; - return $this; - } - - /** - * Retrieve the DocParser instance - * - * If none is registered, lazy-loads a new instance. - * - * @return DocParser - */ - public function getDocParser() - { - if (! $this->docParser instanceof DocParser) { - $this->setDocParser(new DocParser()); - } - - return $this->docParser; - } - - /** - * Handle annotation creation - * - * @param EventInterface $e - * @return false|\stdClass - */ - public function onCreateAnnotation(EventInterface $e) - { - $annotationClass = $e->getParam('class', false); - if (! $annotationClass) { - return false; - } - - if (! isset($this->allowedAnnotations[$annotationClass])) { - return false; - } - - $annotationString = $e->getParam('raw', false); - if (! $annotationString) { - return false; - } - - // Annotation classes provided by the AnnotationScanner are already - // resolved to fully-qualified class names. Adding the global namespace - // prefix allows the Doctrine annotation parser to locate the annotation - // class correctly. - $annotationString = preg_replace('/^(@)/', '$1\\', $annotationString); - - $parser = $this->getDocParser(); - $annotations = $parser->parse($annotationString); - if (empty($annotations)) { - return false; - } - - $annotation = array_shift($annotations); - if (! is_object($annotation)) { - return false; - } - - return $annotation; - } - - /** - * Specify an allowed annotation class - * - * @param string $annotation - * @return DoctrineAnnotationParser - */ - public function registerAnnotation($annotation) - { - $this->allowedAnnotations[$annotation] = true; - return $this; - } - - /** - * Set many allowed annotations at once - * - * @param array|Traversable $annotations Array or traversable object of - * annotation class names - * @throws Exception\InvalidArgumentException - * @return DoctrineAnnotationParser - */ - public function registerAnnotations($annotations) - { - if (! is_array($annotations) && ! $annotations instanceof Traversable) { - throw new Exception\InvalidArgumentException(sprintf( - '%s: expects an array or Traversable; received "%s"', - __METHOD__, - is_object($annotations) ? get_class($annotations) : gettype($annotations) - )); - } - - foreach ($annotations as $annotation) { - $this->allowedAnnotations[$annotation] = true; - } - - return $this; - } -} diff --git a/src/Annotation/Parser/GenericAnnotationParser.php b/src/Annotation/Parser/GenericAnnotationParser.php deleted file mode 100644 index 6515e775..00000000 --- a/src/Annotation/Parser/GenericAnnotationParser.php +++ /dev/null @@ -1,237 +0,0 @@ -getParam('class', false); - if (! $class || ! $this->hasAnnotation($class)) { - return false; - } - - $content = $e->getParam('content', ''); - $content = trim($content, '()'); - - if ($this->hasAlias($class)) { - $class = $this->resolveAlias($class); - } - - $index = array_search($class, $this->annotationNames); - $annotation = $this->annotations[$index]; - - $newAnnotation = clone $annotation; - if ($content) { - $newAnnotation->initialize($content); - } - - return $newAnnotation; - } - - /** - * Register annotations - * - * @param string|AnnotationInterface $annotation String class name of an - * AnnotationInterface implementation, or actual instance - * @return void - * @throws Exception\InvalidArgumentException - */ - public function registerAnnotation($annotation) - { - $class = false; - if (is_string($annotation) && class_exists($annotation)) { - $class = $annotation; - $annotation = new $annotation(); - } - - if (! $annotation instanceof AnnotationInterface) { - throw new Exception\InvalidArgumentException(sprintf( - '%s: expects an instance of %s\AnnotationInterface; received "%s"', - __METHOD__, - __NAMESPACE__, - is_object($annotation) ? get_class($annotation) : gettype($annotation) - )); - } - - $class = $class ?: get_class($annotation); - - if (in_array($class, $this->annotationNames)) { - throw new Exception\InvalidArgumentException(sprintf( - 'An annotation for this class %s already exists', - $class - )); - } - - $this->annotations[] = $annotation; - $this->annotationNames[] = $class; - } - - /** - * Register many annotations at once - * - * @param array|Traversable $annotations - * @throws Exception\InvalidArgumentException - * @return GenericAnnotationParser - */ - public function registerAnnotations($annotations) - { - if (! is_array($annotations) && ! $annotations instanceof Traversable) { - throw new Exception\InvalidArgumentException(sprintf( - '%s: expects an array or Traversable; received "%s"', - __METHOD__, - is_object($annotations) ? get_class($annotations) : gettype($annotations) - )); - } - - foreach ($annotations as $annotation) { - $this->registerAnnotation($annotation); - } - - return $this; - } - - /** - * Checks if the manager has annotations for a class - * - * @param string $class - * @return bool - */ - public function hasAnnotation($class) - { - if (in_array($class, $this->annotationNames)) { - return true; - } - - if ($this->hasAlias($class)) { - return true; - } - - return false; - } - - /** - * Alias an annotation name - * - * @param string $alias - * @param string $class May be either a registered annotation name or another alias - * @throws Exception\InvalidArgumentException - * @return GenericAnnotationParser - */ - public function setAlias($alias, $class) - { - if (! in_array($class, $this->annotationNames) && ! $this->hasAlias($class)) { - throw new Exception\InvalidArgumentException(sprintf( - '%s: Cannot alias "%s" to "%s", as class "%s" is not currently a registered annotation or alias', - __METHOD__, - $alias, - $class, - $class - )); - } - - $alias = $this->normalizeAlias($alias); - $this->aliases[$alias] = $class; - - return $this; - } - - /** - * Normalize an alias name - * - * @param string $alias - * @return string - */ - protected function normalizeAlias($alias) - { - return strtolower(str_replace(['-', '_', ' ', '\\', '/'], '', $alias)); - } - - /** - * Do we have an alias by the provided name? - * - * @param string $alias - * @return bool - */ - protected function hasAlias($alias) - { - $alias = $this->normalizeAlias($alias); - - return isset($this->aliases[$alias]); - } - - /** - * Resolve an alias to a class name - * - * @param string $alias - * @return string - */ - protected function resolveAlias($alias) - { - do { - $normalized = $this->normalizeAlias($alias); - $class = $this->aliases[$normalized]; - } while ($this->hasAlias($class)); - - return $class; - } -} diff --git a/src/Annotation/Parser/ParserInterface.php b/src/Annotation/Parser/ParserInterface.php deleted file mode 100644 index f27ea471..00000000 --- a/src/Annotation/Parser/ParserInterface.php +++ /dev/null @@ -1,39 +0,0 @@ -annotationManager = $annotationManager; - $this->docComment = $docComment; - $this->nameInformation = $nameInformation; - $this->scan($this->tokenize()); - } - - /** - * @param NameInformation $nameInformation - */ - public function setNameInformation(NameInformation $nameInformation) - { - $this->nameInformation = $nameInformation; - } - - /** - * @param array $tokens - */ - protected function scan(array $tokens) - { - $annotations = []; - $annotationIndex = -1; - $contentEnd = false; - - reset($tokens); - - SCANNER_TOP: - $token = current($tokens); - - switch ($token[0]) { - case 'ANNOTATION_CLASS': - $contentEnd = false; - $annotationIndex++; - $class = substr($token[1], 1); - $class = $this->nameInformation->resolveName($class); - $annotations[$annotationIndex] = [$class, null]; - goto SCANNER_CONTINUE; - // goto no break needed - - case 'ANNOTATION_CONTENT_START': - $annotations[$annotationIndex][1] = ''; - // fall-through - - case 'ANNOTATION_CONTENT_END': - case 'ANNOTATION_CONTENT': - case 'ANNOTATION_WHITESPACE': - case 'ANNOTATION_NEWLINE': - if (! $contentEnd - && isset($annotations[$annotationIndex]) - && is_string($annotations[$annotationIndex][1]) - ) { - $annotations[$annotationIndex][1] .= $token[1]; - } - - if ($token[0] === 'ANNOTATION_CONTENT_END') { - $contentEnd = true; - } - - goto SCANNER_CONTINUE; - // goto no break needed - } - - SCANNER_CONTINUE: - if (next($tokens) === false) { - goto SCANNER_END; - } - goto SCANNER_TOP; - - SCANNER_END: - - foreach ($annotations as $annotation) { - $annotation[] = '@' . $annotation[0] . $annotation[1]; - $annotationObject = $this->annotationManager->createAnnotation($annotation); - if ($annotationObject) { - $this->append($annotationObject); - } - } - } - - /** - * @return array - */ - protected function tokenize() - { - static $CONTEXT_DOCBLOCK = 0x01; - static $CONTEXT_ASTERISK = 0x02; - static $CONTEXT_CLASS = 0x04; - static $CONTEXT_CONTENT = 0x08; - - $context = 0x00; - $stream = $this->docComment; - $streamIndex = null; - $tokens = []; - $tokenIndex = null; - $currentChar = null; - $currentWord = null; - $currentLine = null; - - $annotationParentCount = 0; - - $MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use ( - &$stream, - &$streamIndex, - &$currentChar, - &$currentWord, - &$currentLine - ) { - $positionsForward = $positionsForward > 0 ? $positionsForward : 1; - $streamIndex = $streamIndex === null ? 0 : $streamIndex + $positionsForward; - if (! isset($stream[$streamIndex])) { - $currentChar = false; - - return false; - } - $currentChar = $stream[$streamIndex]; - $matches = []; - $currentLine = preg_match('#(.*?)(?:\n|\r\n?)#', $stream, $matches, null, $streamIndex) === 1 - ? $matches[1] - : substr($stream, $streamIndex); - if ($currentChar === ' ') { - $currentWord = preg_match('#( +)#', $currentLine, $matches) === 1 ? $matches[1] : $currentLine; - } else { - $currentWord = ($matches = strpos($currentLine, ' ')) !== false - ? substr($currentLine, 0, $matches) - : $currentLine; - } - - return $currentChar; - }; - $MACRO_STREAM_ADVANCE_WORD = function () use (&$currentWord, &$MACRO_STREAM_ADVANCE_CHAR) { - return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentWord)); - }; - $MACRO_STREAM_ADVANCE_LINE = function () use (&$currentLine, &$MACRO_STREAM_ADVANCE_CHAR) { - return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine)); - }; - $MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) { - $tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1; - $tokens[$tokenIndex] = ['ANNOTATION_UNKNOWN', '']; - }; - $MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) { - $tokens[$tokenIndex][0] = $type; - }; - $MACRO_TOKEN_APPEND_CHAR = function () use (&$currentChar, &$tokens, &$tokenIndex) { - $tokens[$tokenIndex][1] .= $currentChar; - }; - $MACRO_TOKEN_APPEND_WORD = function () use (&$currentWord, &$tokens, &$tokenIndex) { - $tokens[$tokenIndex][1] .= $currentWord; - }; - $MACRO_TOKEN_APPEND_LINE = function () use (&$currentLine, &$tokens, &$tokenIndex) { - $tokens[$tokenIndex][1] .= $currentLine; - }; - $MACRO_HAS_CONTEXT = function ($which) use (&$context) { - return ($context & $which) === $which; - }; - - $MACRO_STREAM_ADVANCE_CHAR(); - $MACRO_TOKEN_ADVANCE(); - - TOKENIZER_TOP: - - if ($context === 0x00 && $currentChar === '/' && $currentWord === '/**') { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_COMMENTSTART'); - $MACRO_TOKEN_APPEND_WORD(); - $MACRO_TOKEN_ADVANCE(); - $context |= $CONTEXT_DOCBLOCK; - $context |= $CONTEXT_ASTERISK; - if ($MACRO_STREAM_ADVANCE_WORD() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($MACRO_HAS_CONTEXT($CONTEXT_CLASS)) { - if (in_array($currentChar, [' ', '(', "\n", "\r"])) { - $context &= ~$CONTEXT_CLASS; - $MACRO_TOKEN_ADVANCE(); - } else { - $MACRO_TOKEN_APPEND_CHAR(); - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - } - - // Since we don't know what line endings are used in the file, we check for all scenarios. If we find a - // carriage return (\r), we check the next character for a line feed (\n). If so we consume it and act as - // if the carriage return was a line feed. - $lineEnded = $currentChar === "\n"; - if ($currentChar === "\r") { - $lineEnded = true; - - $nextChar = $MACRO_STREAM_ADVANCE_CHAR(); - if ($nextChar !== "\n") { - $streamIndex--; - } - - $currentChar = "\n"; - } - - if ($lineEnded) { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_NEWLINE'); - $MACRO_TOKEN_APPEND_CHAR(); - $MACRO_TOKEN_ADVANCE(); - $context &= ~$CONTEXT_ASTERISK; - $context &= ~$CONTEXT_CLASS; - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($currentChar === ' ') { - $MACRO_TOKEN_SET_TYPE( - $MACRO_HAS_CONTEXT($CONTEXT_ASTERISK) - ? 'ANNOTATION_WHITESPACE' - : 'ANNOTATION_WHITESPACE_INDENT' - ); - $MACRO_TOKEN_APPEND_WORD(); - $MACRO_TOKEN_ADVANCE(); - if ($MACRO_STREAM_ADVANCE_WORD() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($MACRO_HAS_CONTEXT($CONTEXT_CONTENT) && $MACRO_HAS_CONTEXT($CONTEXT_ASTERISK)) { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT'); - $annotationParentCount += substr_count($currentWord, '('); - $annotationParentCount -= substr_count($currentWord, ')'); - - if ($annotationParentCount === 0) { - $context &= ~$CONTEXT_CONTENT; - $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT_END'); - } - $MACRO_TOKEN_APPEND_WORD(); - $MACRO_TOKEN_ADVANCE(); - if ($MACRO_STREAM_ADVANCE_WORD() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($currentChar === '(' && $tokens[$tokenIndex - 1][0] === 'ANNOTATION_CLASS') { - $context |= $CONTEXT_CONTENT; - $annotationParentCount = 1; - $MACRO_TOKEN_SET_TYPE('ANNOTATION_CONTENT_START'); - $MACRO_TOKEN_APPEND_CHAR(); - $MACRO_TOKEN_ADVANCE(); - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($MACRO_HAS_CONTEXT($CONTEXT_DOCBLOCK) && $currentWord === '*/') { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_COMMENTEND'); - $MACRO_TOKEN_APPEND_WORD(); - $MACRO_TOKEN_ADVANCE(); - $context &= ~$CONTEXT_DOCBLOCK; - if ($MACRO_STREAM_ADVANCE_WORD() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($currentChar === '*') { - if ($MACRO_HAS_CONTEXT($CONTEXT_DOCBLOCK) && ($MACRO_HAS_CONTEXT($CONTEXT_ASTERISK))) { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_IGNORE'); - } else { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_ASTERISK'); - $context |= $CONTEXT_ASTERISK; - } - $MACRO_TOKEN_APPEND_CHAR(); - $MACRO_TOKEN_ADVANCE(); - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - if ($currentChar === '@') { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_CLASS'); - $context |= $CONTEXT_CLASS; - $MACRO_TOKEN_APPEND_CHAR(); - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - goto TOKENIZER_TOP; - } - - TOKENIZER_CONTINUE: - - if ($context && $CONTEXT_CONTENT) { - $MACRO_TOKEN_APPEND_CHAR(); - if ($MACRO_STREAM_ADVANCE_CHAR() === false) { - goto TOKENIZER_END; - } - } else { - $MACRO_TOKEN_SET_TYPE('ANNOTATION_IGNORE'); - $MACRO_TOKEN_APPEND_LINE(); - $MACRO_TOKEN_ADVANCE(); - if ($MACRO_STREAM_ADVANCE_LINE() === false) { - goto TOKENIZER_END; - } - } - goto TOKENIZER_TOP; - - TOKENIZER_END: - - array_pop($tokens); - - return $tokens; - } -} diff --git a/test/Annotation/AnnotationManagerTest.php b/test/Annotation/AnnotationManagerTest.php deleted file mode 100644 index ae2f5937..00000000 --- a/test/Annotation/AnnotationManagerTest.php +++ /dev/null @@ -1,63 +0,0 @@ -markTestSkipped( - 'Enable TESTS_ZEND_CODE_ANNOTATION_DOCTRINE_SUPPORT to test doctrine annotation parsing' - ); - } - - $this->manager = new Annotation\AnnotationManager(); - } - - public function testAllowsMultipleParsingStrategies() - { - $genericParser = new Annotation\Parser\GenericAnnotationParser(); - $genericParser->registerAnnotation(TestAsset\Foo::class); - $doctrineParser = new Annotation\Parser\DoctrineAnnotationParser(); - $doctrineParser->registerAnnotation(TestAsset\DoctrineAnnotation::class); - - $this->manager->attach($genericParser); - $this->manager->attach($doctrineParser); - - $reflection = new Reflection\ClassReflection(TestAsset\EntityWithMixedAnnotations::class); - $prop = $reflection->getProperty('test'); - $annotations = $prop->getAnnotations($this->manager); - - self::assertTrue($annotations->hasAnnotation(TestAsset\Foo::class)); - self::assertTrue($annotations->hasAnnotation(TestAsset\DoctrineAnnotation::class)); - self::assertFalse($annotations->hasAnnotation(TestAsset\Bar::class)); - - foreach ($annotations as $annotation) { - switch (get_class($annotation)) { - case TestAsset\Foo::class: - self::assertEquals('first', $annotation->content); - break; - case TestAsset\DoctrineAnnotation::class: - self::assertEquals(['foo' => 'bar', 'bar' => 'baz'], $annotation->value); - break; - default: - $this->fail('Received unexpected annotation "' . get_class($annotation) . '"'); - } - } - } -} diff --git a/test/Annotation/DoctrineAnnotationParserTest.php b/test/Annotation/DoctrineAnnotationParserTest.php deleted file mode 100644 index 1f5ab2c4..00000000 --- a/test/Annotation/DoctrineAnnotationParserTest.php +++ /dev/null @@ -1,100 +0,0 @@ -markTestSkipped( - 'Enable TESTS_ZEND_CODE_ANNOTATION_DOCTRINE_SUPPORT to test doctrine annotation parsing' - ); - } - - $this->parser = new DoctrineAnnotationParser(); - } - - public function getEvent() - { - $event = new Event(); - $event->setParams([ - 'class' => __NAMESPACE__ . '\TestAsset\DoctrineAnnotation', - 'content' => '(foo="bar")', - 'raw' => '@' . __NAMESPACE__ . '\TestAsset\DoctrineAnnotation(foo="bar")', - ]); - return $event; - } - - public function testParserCreatesNewAnnotationInstances() - { - $this->parser->registerAnnotation(__NAMESPACE__ . '\TestAsset\DoctrineAnnotation'); - - $event = $this->getEvent(); - $test = $this->parser->onCreateAnnotation($event); - self::assertInstanceOf(__NAMESPACE__ . '\TestAsset\DoctrineAnnotation', $test); - self::assertEquals(['foo' => 'bar'], $test->value); - } - - public function testReturnsFalseDuringCreationIfAnnotationIsNotRegistered() - { - $event = $this->getEvent(); - self::assertFalse($this->parser->onCreateAnnotation($event)); - } - - public function testReturnsFalseClassNotSet() - { - self::assertFalse($this->parser->onCreateAnnotation(new Event())); - } - - public function testReturnsFalseRawNotSet() - { - $this->parser->registerAnnotation(__NAMESPACE__ . '\TestAsset\DoctrineAnnotation'); - $event = $this->getEvent(); - $event->setParam('raw', false); - - self::assertFalse($this->parser->onCreateAnnotation($event)); - } - - public function testReturnsFalseEmptyAnnotations() - { - $this->parser->registerAnnotation(__NAMESPACE__ . '\TestAsset\DoctrineAnnotation'); - $event = $this->getEvent(); - $event->setParam('raw', 'foo'); - self::assertFalse($this->parser->onCreateAnnotation($event)); - } - - public function testRegisterAnnotationsThrowsException() - { - $this->expectException(InvalidArgumentException::class); - $this->parser->registerAnnotations('some string'); - } - - public function testRegisterAnnotations() - { - $this->parser->registerAnnotations([__NAMESPACE__ . '\TestAsset\DoctrineAnnotation']); - $event = $this->getEvent(); - $test = $this->parser->onCreateAnnotation($event); - self::assertInstanceOf(__NAMESPACE__ . '\TestAsset\DoctrineAnnotation', $test); - self::assertEquals(['foo' => 'bar'], $test->value); - } -} diff --git a/test/Annotation/GenericAnnotationParserTest.php b/test/Annotation/GenericAnnotationParserTest.php deleted file mode 100644 index 22d7c551..00000000 --- a/test/Annotation/GenericAnnotationParserTest.php +++ /dev/null @@ -1,127 +0,0 @@ -parser = new Annotation\Parser\GenericAnnotationParser(); - } - - public function getFooEvent() - { - $event = new Event(); - $event->setParams([ - 'class' => __NAMESPACE__ . '\TestAsset\Foo', - 'content' => '(test content)', - 'raw' => '@' . __NAMESPACE__ . '\TestAsset\Foo(test content)', - ]); - return $event; - } - - public function testParserKeepsTrackOfAllowedAnnotations() - { - $this->parser->registerAnnotation(new TestAsset\Foo()); - $this->parser->registerAnnotation(new TestAsset\Bar()); - - self::assertTrue($this->parser->hasAnnotation(__NAMESPACE__ . '\TestAsset\Foo')); - self::assertTrue($this->parser->hasAnnotation(__NAMESPACE__ . '\TestAsset\Bar')); - self::assertFalse($this->parser->hasAnnotation(__NAMESPACE__ . '\TestAsset\Bogus')); - } - - public function testParserCreatesNewAnnotationInstances() - { - $foo = new TestAsset\Foo(); - $this->parser->registerAnnotation($foo); - - $event = $this->getFooEvent(); - $test = $this->parser->onCreateAnnotation($event); - self::assertInstanceOf(__NAMESPACE__ . '\TestAsset\Foo', $test); - self::assertNotSame($foo, $test); - self::assertEquals('test content', $test->content); - } - - public function testReturnsFalseDuringCreationIfAnnotationIsNotRegistered() - { - $event = $this->getFooEvent(); - self::assertFalse($this->parser->onCreateAnnotation($event)); - } - - public function testParserAllowsPassingArrayOfAnnotationInstances() - { - $this->parser->registerAnnotations([ - new TestAsset\Foo(), - new TestAsset\Bar(), - ]); - self::assertTrue($this->parser->hasAnnotation(__NAMESPACE__ . '\TestAsset\Foo')); - self::assertTrue($this->parser->hasAnnotation(__NAMESPACE__ . '\TestAsset\Bar')); - } - - public function testAllowsSpecifyingAliases() - { - $bar = new TestAsset\Bar(); - $this->parser->registerAnnotation($bar); - $this->parser->setAlias(__NAMESPACE__ . '\TestAsset\Foo', get_class($bar)); - - $event = $this->getFooEvent(); - $test = $this->parser->onCreateAnnotation($event); - self::assertInstanceOf(__NAMESPACE__ . '\TestAsset\Bar', $test); - self::assertNotSame($bar, $test); - self::assertEquals('test content', $test->content); - } - - public function testRegisterAnnotationAllowsAnnotationInterfaceOnly() - { - $this->expectException(InvalidArgumentException::class); - $this->parser->registerAnnotation(new \stdClass()); - } - - public function testAllowRegistrationOnceOnly() - { - $bar = new TestAsset\Bar(); - $this->parser->registerAnnotation($bar); - - $this->expectException(InvalidArgumentException::class); - $this->parser->registerAnnotation($bar); - } - - public function testRegisterAnnotations() - { - $this->parser->registerAnnotations([new TestAsset\Foo()]); - $event = $this->getFooEvent(); - $test = $this->parser->onCreateAnnotation($event); - self::assertInstanceOf(__NAMESPACE__ . '\TestAsset\Foo', $test); - } - - public function testRegisterAnnotationsThrowsException() - { - $this->expectException(InvalidArgumentException::class); - $this->parser->registerAnnotations('some string'); - } - - public function testSetAliasNotRegisteredClassThrowsException() - { - $this->expectException(InvalidArgumentException::class); - $this->parser->setAlias('bar', 'foo'); - } -} diff --git a/test/Annotation/TestAsset/Bar.php b/test/Annotation/TestAsset/Bar.php deleted file mode 100644 index 6b58b282..00000000 --- a/test/Annotation/TestAsset/Bar.php +++ /dev/null @@ -1,22 +0,0 @@ -content = $content; - } -} diff --git a/test/Annotation/TestAsset/DoctrineAnnotation.php b/test/Annotation/TestAsset/DoctrineAnnotation.php deleted file mode 100644 index 59d08b46..00000000 --- a/test/Annotation/TestAsset/DoctrineAnnotation.php +++ /dev/null @@ -1,23 +0,0 @@ -value = $value; - } -} diff --git a/test/Annotation/TestAsset/EntityWithAnnotations.php b/test/Annotation/TestAsset/EntityWithAnnotations.php deleted file mode 100644 index bfe8efe2..00000000 --- a/test/Annotation/TestAsset/EntityWithAnnotations.php +++ /dev/null @@ -1,27 +0,0 @@ -content = $content; - } -} diff --git a/test/Scanner/AnnotationScannerTest.php b/test/Scanner/AnnotationScannerTest.php deleted file mode 100644 index 965cdf5a..00000000 --- a/test/Scanner/AnnotationScannerTest.php +++ /dev/null @@ -1,59 +0,0 @@ -registerAnnotations([ - $foo = new TestAsset\Annotation\Foo(), - $bar = new TestAsset\Annotation\Bar(), - ]); - $annotationManager->attach($parser); - - $docComment = '/**' . $newLine - . ' * @Test\Foo(\'anything I want()' . $newLine - . ' * to be\')' . $newLine - . ' * @Test\Bar' . $newLine . ' */'; - - $nameInfo = new NameInformation(); - $nameInfo->addUse('ZendTest\Code\Scanner\TestAsset\Annotation', 'Test'); - - $annotationScanner = new AnnotationScanner($annotationManager, $docComment, $nameInfo); - self::assertEquals(get_class($foo), get_class($annotationScanner[0])); - self::assertEquals("'anything I want()\n to be'", $annotationScanner[0]->getContent()); - self::assertEquals(get_class($bar), get_class($annotationScanner[1])); - } - - public function newLine() - { - return [ - ["\n"], - ["\r"], - ["\r\n"], - ]; - } -} diff --git a/test/Scanner/TestAsset/Annotation/Bar.php b/test/Scanner/TestAsset/Annotation/Bar.php deleted file mode 100644 index 8e852167..00000000 --- a/test/Scanner/TestAsset/Annotation/Bar.php +++ /dev/null @@ -1,22 +0,0 @@ -content = $content; - } -} diff --git a/test/Scanner/TestAsset/Annotation/Foo.php b/test/Scanner/TestAsset/Annotation/Foo.php deleted file mode 100644 index adafb857..00000000 --- a/test/Scanner/TestAsset/Annotation/Foo.php +++ /dev/null @@ -1,28 +0,0 @@ -content = $content; - } - - public function getContent() - { - return $this->content; - } - -}