forked from doctrine/common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaticReflectionParserTest.php
99 lines (92 loc) · 3.43 KB
/
StaticReflectionParserTest.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Doctrine\Tests\Common\Reflection;
use Doctrine\Tests\Common\Reflection\NoParent;
use Doctrine\Tests\Common\Reflection\Dummies\NoParent as NoParentDummy;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Common\Reflection\StaticReflectionParser;
use Doctrine\Common\Reflection\Psr0FindFile;
use ReflectionException;
class StaticReflectionParserTest extends DoctrineTestCase
{
/**
* @dataProvider parentClassData
*
* @param bool $classAnnotationOptimize
* @param string $parsedClassName
* @param string $expectedClassName
*
* @return void
*/
public function testParentClass($classAnnotationOptimize, $parsedClassName, $expectedClassName)
{
// If classed annotation optimization is enabled the properties tested
// below cannot be found.
if ($classAnnotationOptimize) {
$this->expectException(ReflectionException::class);
}
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
$paths = [
'Doctrine\\Tests' => [$testsRoot],
];
$staticReflectionParser = new StaticReflectionParser($parsedClassName, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
self::assertEquals($expectedClassName, $declaringClassName);
self::assertEquals($parsedClassName, $staticReflectionParser->getReflectionClass()->getName());
}
/**
* @return array
*/
public function parentClassData()
{
$data = [];
$noParentClassName = NoParent::class;
$dummyParentClassName = NoParentDummy::class;
foreach ([false, true] as $classAnnotationOptimize) {
$data[] = [
$classAnnotationOptimize, $noParentClassName, $noParentClassName,
];
$data[] = [
$classAnnotationOptimize, FullyClassifiedParent::class, $noParentClassName,
];
$data[] = [
$classAnnotationOptimize, SameNamespaceParent::class, $noParentClassName,
];
$data[] = [
$classAnnotationOptimize, DeeperNamespaceParent::class, $dummyParentClassName,
];
$data[] = [
$classAnnotationOptimize, UseParent::class, $dummyParentClassName,
];
}
return $data;
}
/**
* @dataProvider classAnnotationOptimize
*/
public function testClassAnnotationOptimizedParsing($class, $classAnnotationOptimize)
{
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
$paths = [
'Doctrine\\Tests' => [$testsRoot],
];
$staticReflectionParser = new StaticReflectionParser($class, new Psr0FindFile($paths), $classAnnotationOptimize);
$expectedDocComment = '/**
* @Annotation(
* key = "value"
* )
*/';
self::assertEquals($expectedDocComment, $staticReflectionParser->getDocComment('class'));
}
/**
* @return array
*/
public function classAnnotationOptimize()
{
return [
[ExampleAnnotationClass::class, false],
[ExampleAnnotationClass::class, true],
[AnnotationClassWithScopeResolution::class, false],
[AnnotationClassWithScopeResolution::class, true],
];
}
}