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) . '"'); } } }
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); }
/** * 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 testScannerWorks() { $annotationManager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotations(array($foo = new TestAsset\Annotation\Foo(), $bar = new TestAsset\Annotation\Bar())); $annotationManager->attach($parser); $docComment = '/**' . "\n" . ' * @Test\\Foo(\'anything I want()' . "\n" . ' * to be\')' . "\n" . ' * @Test\\Bar' . "\n */"; $nameInfo = new NameInformation(); $nameInfo->addUse('ZendTest\\Code\\Scanner\\TestAsset\\Annotation', 'Test'); $annotationScanner = new AnnotationScanner($annotationManager, $docComment, $nameInfo); $this->assertEquals(get_class($foo), get_class($annotationScanner[0])); $this->assertEquals("'anything I want()\n to be'", $annotationScanner[0]->getContent()); $this->assertEquals(get_class($bar), get_class($annotationScanner[1])); }
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); }
/** * Normalize an alias name * * @param string $alias * @return string */ protected function normalizeAlias($alias) { $alias = substr($alias, strpos($alias, '\\MS'), strlen($alias)); return parent::normalizeAlias($alias); }