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 testAllowsMultipleParsingStrategies() { $genericParser = new Annotation\Parser\GenericAnnotationParser(); $genericParser->registerAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo'); $doctrineParser = new Annotation\Parser\DoctrineAnnotationParser(); $doctrineParser->registerAnnotation(__NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation'); $this->manager->attach($genericParser); $this->manager->attach($doctrineParser); $reflection = new Reflection\ClassReflection(__NAMESPACE__ . '\\TestAsset\\EntityWithMixedAnnotations'); $prop = $reflection->getProperty('test'); $annotations = $prop->getAnnotations($this->manager); $this->assertTrue($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo')); $this->assertTrue($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation')); $this->assertFalse($annotations->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Bar')); foreach ($annotations as $annotation) { switch (get_class($annotation)) { case __NAMESPACE__ . '\\TestAsset\\Foo': $this->assertEquals('first', $annotation->content); break; case __NAMESPACE__ . '\\TestAsset\\DoctrineAnnotation': $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $annotation->value); break; default: $this->fail('Received unexpected annotation "' . get_class($annotation) . '"'); } } }
/** * Create default annotation manager * * @return AnnotationManager */ public function createDefaultAnnotationManager() { $annotationManager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotation(new Annotation\Inject()); $annotationManager->attach($parser); return $annotationManager; }
public function testAnnotationScanningIsPossible() { $manager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotation(new TestAsset\SampleAnnotation()); $manager->attach($parser); $property = new \Zend\Code\Reflection\PropertyReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass2', '_prop2'); $annotations = $property->getAnnotations($manager); $this->assertInstanceOf('Zend\\Code\\Annotation\\AnnotationCollection', $annotations); $this->assertTrue($annotations->hasAnnotation('ZendTest\\Code\\Reflection\\TestAsset\\SampleAnnotation')); $found = false; foreach ($annotations as $key => $annotation) { if (!$annotation instanceof TestAsset\SampleAnnotation) { continue; } $this->assertEquals(get_class($annotation) . ': {"foo":"bar"}', $annotation->content); $found = true; break; } $this->assertTrue($found); }