Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added class annotation scanner

  • Loading branch information...
commit feae790e1577950ff6c5c2955d3af5bea5514b41 1 parent d959262
@Rovak Rovak authored
View
16 library/Zend/Code/Scanner/ClassScanner.php
@@ -10,7 +10,7 @@
namespace Zend\Code\Scanner;
-use Zend\Code\Annotation\AnnotationManager;
+use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
@@ -107,9 +107,17 @@ public function __construct(array $classTokens, NameInformation $nameInformation
$this->nameInformation = $nameInformation;
}
- public function getAnnotations()
+ /**
+ * @param Annotation\AnnotationManager $annotationManager
+ * @return Annotation\AnnotationCollection
+ */
+ public function getAnnotations(Annotation\AnnotationManager $annotationManager)
{
- return array();
+ if (($docComment = $this->getDocComment()) == '') {
+ return false;
+ }
+
+ return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
}
public function getDocComment()
@@ -678,4 +686,4 @@ protected function scan()
return;
}
-}
+}
View
8 tests/ZendTest/Code/Annotation/TestAsset/EntityWithAnnotations.php
@@ -10,6 +10,12 @@
namespace ZendTest\Code\Annotation\TestAsset;
+/**
+ * @Foo(first)
+ * @Bar(second)
+ * @Bar(third)
+ * @Bogus(does not exist)
+ */
class EntityWithAnnotations
{
/**
@@ -19,4 +25,4 @@ class EntityWithAnnotations
* @Bogus(does not exist)
*/
public $test;
-}
+}
View
29 tests/ZendTest/Code/Scanner/ClassScannerTest.php
@@ -11,10 +11,24 @@
namespace ZendTest\Code\Scanner;
use Zend\Code\Scanner\FileScanner;
+use Zend\Code\Annotation;
use PHPUnit_Framework_TestCase as TestCase;
class ClassScannerTest extends TestCase
{
+ protected $manager;
+
+ public function setUp()
+ {
+ $this->manager = new Annotation\AnnotationManager();
+
+ $genericParser = new Annotation\Parser\GenericAnnotationParser();
+ $genericParser->registerAnnotation('ZendTest\Code\Annotation\TestAsset\Foo');
+ $genericParser->registerAnnotation('ZendTest\Code\Annotation\TestAsset\Bar');
+
+ $this->manager->attach($genericParser);
+ }
+
public function testClassScannerHasClassInformation()
{
$file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
@@ -84,5 +98,18 @@ public function testClassScannerCanReturnLineNumbers()
$this->assertEquals(11, $class->getLineStart());
$this->assertEquals(34, $class->getLineEnd());
}
+
+ public function testClassScannerCanScanAnnotations()
+ {
+ $file = new FileScanner(__DIR__ . '/../Annotation/TestAsset/EntityWithAnnotations.php');
+ $class = $file->getClass('ZendTest\Code\Annotation\TestAsset\EntityWithAnnotations');
+ $annotations = $class->getAnnotations($this->manager);
+
+ $this->assertTrue($annotations->hasAnnotation('ZendTest\Code\Annotation\TestAsset\Foo'));
+ $this->assertTrue($annotations->hasAnnotation('ZendTest\Code\Annotation\TestAsset\Bar'));
-}
+ $this->assertEquals('first', $annotations[0]->content);
+ $this->assertEquals('second', $annotations[1]->content);
+ $this->assertEquals('third', $annotations[2]->content);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.