forked from zendframework/zend-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnotationManagerTest.php
58 lines (49 loc) · 2.34 KB
/
AnnotationManagerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Code\Annotation;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Code\Annotation;
use Zend\Code\Reflection;
class AnnotationManagerTest extends TestCase
{
public function setUp()
{
if (!getenv('TESTS_ZEND_CODE_ANNOTATION_DOCTRINE_SUPPORT')) {
$this->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(__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(['foo' => 'bar', 'bar' => 'baz'], $annotation->value);
break;
default:
$this->fail('Received unexpected annotation "' . get_class($annotation) . '"');
}
}
}
}