StaticReflectionParserTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Doctrine\Tests\Common\Reflection;
  3. use Doctrine\Tests\DoctrineTestCase;
  4. use Doctrine\Common\Reflection\StaticReflectionParser;
  5. use Doctrine\Common\Reflection\Psr0FindFile;
  6. class StaticReflectionParserTest extends DoctrineTestCase
  7. {
  8. /**
  9. * @dataProvider classAnnotationOptimize
  10. *
  11. * @param bool $classAnnotationOptimize
  12. *
  13. * @return void
  14. */
  15. public function testParentClass($classAnnotationOptimize)
  16. {
  17. $testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
  18. $paths = array(
  19. 'Doctrine\\Tests' => array($testsRoot),
  20. );
  21. $noParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\NoParent';
  22. $staticReflectionParser = new StaticReflectionParser($noParentClassName, new Psr0FindFile($paths), $classAnnotationOptimize);
  23. $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
  24. $this->assertEquals($noParentClassName, $declaringClassName);
  25. $className = 'Doctrine\\Tests\\Common\\Reflection\\FullyClassifiedParent';
  26. $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
  27. $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
  28. $this->assertEquals($noParentClassName, $declaringClassName);
  29. $className = 'Doctrine\\Tests\\Common\\Reflection\\SameNamespaceParent';
  30. $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
  31. $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
  32. $this->assertEquals($noParentClassName, $declaringClassName);
  33. $dummyParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\Dummies\\NoParent';
  34. $className = 'Doctrine\\Tests\\Common\\Reflection\\DeeperNamespaceParent';
  35. $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
  36. $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
  37. $this->assertEquals($dummyParentClassName, $declaringClassName);
  38. $className = 'Doctrine\\Tests\\Common\\Reflection\\UseParent';
  39. $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
  40. $declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
  41. $this->assertEquals($dummyParentClassName, $declaringClassName);
  42. }
  43. /**
  44. * @return array
  45. */
  46. public function classAnnotationOptimize()
  47. {
  48. return array(
  49. array(false),
  50. array(true)
  51. );
  52. }
  53. }