Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'fix/classannotations' of https://github.com/Rovak/zf2 i…

…nto feature/code-scanner-class-annotations
  • Loading branch information...
commit f13575cf60dcd3980f59ce823ebb300e0c7717b3 2 parents b012976 + cb4df59
@weierophinney weierophinney authored
View
14 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()
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
27 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');
@@ -94,4 +108,17 @@ public function testClassScannerCanReturnLineNumbers()
$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.