|
9 | 9 | class StaticReflectionParserTest extends DoctrineTestCase |
10 | 10 | { |
11 | 11 | /** |
12 | | - * @dataProvider classAnnotationOptimize |
| 12 | + * @dataProvider parentClassData |
13 | 13 | * |
14 | 14 | * @param bool $classAnnotationOptimize |
| 15 | + * @param string $parsedClassName |
| 16 | + * @param string $expectedClassName |
15 | 17 | * |
16 | 18 | * @return void |
17 | 19 | */ |
18 | | - public function testParentClass($classAnnotationOptimize) |
| 20 | + public function testParentClass($classAnnotationOptimize, $parsedClassName, $expectedClassName) |
19 | 21 | { |
| 22 | + // If classed annotation optimization is enabled the properties tested |
| 23 | + // below cannot be found. |
| 24 | + if ($classAnnotationOptimize) { |
| 25 | + $this->setExpectedException('ReflectionException'); |
| 26 | + } |
| 27 | + |
20 | 28 | $testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1); |
21 | 29 | $paths = array( |
22 | 30 | 'Doctrine\\Tests' => array($testsRoot), |
23 | 31 | ); |
24 | | - $noParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\NoParent'; |
25 | | - $staticReflectionParser = new StaticReflectionParser($noParentClassName, new Psr0FindFile($paths), $classAnnotationOptimize); |
| 32 | + $staticReflectionParser = new StaticReflectionParser($parsedClassName, new Psr0FindFile($paths), $classAnnotationOptimize); |
26 | 33 | $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName(); |
27 | | - $this->assertEquals($noParentClassName, $declaringClassName); |
| 34 | + $this->assertEquals($expectedClassName, $declaringClassName); |
28 | 35 |
|
29 | | - $className = 'Doctrine\\Tests\\Common\\Reflection\\FullyClassifiedParent'; |
30 | | - $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize); |
31 | | - $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName(); |
32 | | - $this->assertEquals($noParentClassName, $declaringClassName); |
33 | | - |
34 | | - $className = 'Doctrine\\Tests\\Common\\Reflection\\SameNamespaceParent'; |
35 | | - $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize); |
36 | | - $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName(); |
37 | | - $this->assertEquals($noParentClassName, $declaringClassName); |
| 36 | + } |
38 | 37 |
|
| 38 | + /** |
| 39 | + * @return array |
| 40 | + */ |
| 41 | + public function parentClassData() |
| 42 | + { |
| 43 | + $data = array(); |
| 44 | + $noParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\NoParent'; |
39 | 45 | $dummyParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\Dummies\\NoParent'; |
| 46 | + foreach (array(false, true) as $classAnnotationOptimize) { |
| 47 | + $data[] = array( |
| 48 | + $classAnnotationOptimize, $noParentClassName, $noParentClassName, |
| 49 | + ); |
| 50 | + $data[] = array( |
| 51 | + $classAnnotationOptimize, 'Doctrine\\Tests\\Common\\Reflection\\FullyClassifiedParent', $noParentClassName, |
| 52 | + ); |
| 53 | + $data[] = array( |
| 54 | + $classAnnotationOptimize, 'Doctrine\\Tests\\Common\\Reflection\\SameNamespaceParent', $noParentClassName, |
| 55 | + ); |
| 56 | + $data[] = array( |
| 57 | + $classAnnotationOptimize, 'Doctrine\\Tests\\Common\\Reflection\\DeeperNamespaceParent', $dummyParentClassName, |
| 58 | + ); |
| 59 | + $data[] = array( |
| 60 | + $classAnnotationOptimize, 'Doctrine\\Tests\\Common\\Reflection\\UseParent', $dummyParentClassName, |
| 61 | + ); |
| 62 | + } |
| 63 | + return $data; |
| 64 | + } |
40 | 65 |
|
41 | | - $className = 'Doctrine\\Tests\\Common\\Reflection\\DeeperNamespaceParent'; |
42 | | - $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize); |
43 | | - $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName(); |
44 | | - $this->assertEquals($dummyParentClassName, $declaringClassName); |
45 | | - |
46 | | - $className = 'Doctrine\\Tests\\Common\\Reflection\\UseParent'; |
47 | | - $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize); |
48 | | - $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName(); |
49 | | - $this->assertEquals($dummyParentClassName, $declaringClassName); |
50 | | - |
| 66 | + /** |
| 67 | + * @dataProvider classAnnotationOptimize |
| 68 | + */ |
| 69 | + public function testClassAnnotationOptimizedParsing($classAnnotationOptimize) { |
| 70 | + $testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1); |
| 71 | + $paths = array( |
| 72 | + 'Doctrine\\Tests' => array($testsRoot), |
| 73 | + ); |
| 74 | + $staticReflectionParser = new StaticReflectionParser('Doctrine\\Tests\\Common\\Reflection\\ExampleAnnotationClass', new Psr0FindFile($paths), $classAnnotationOptimize); |
| 75 | + $expectedDocComment = '/** |
| 76 | + * @Annotation( |
| 77 | + * key = "value" |
| 78 | + * ) |
| 79 | + */'; |
| 80 | + $this->assertEquals($expectedDocComment, $staticReflectionParser->getDocComment('class')); |
51 | 81 | } |
52 | 82 |
|
53 | 83 | /** |
|
0 commit comments