Browse files

Fixed StaticReflectionParser.

This commit removes the PSR246Test, which is now covered by an updated StaticReflectionParserTest.
  • Loading branch information...
1 parent e410085 commit 81f97bb12c13e6bad0d982bc19d4a3958fd3df1e @BenMorel BenMorel committed Jan 27, 2013
View
19 lib/Doctrine/Common/Reflection/StaticReflectionParser.php
@@ -31,13 +31,20 @@ class StaticReflectionParser implements ReflectionProviderInterface
{
/**
- * The name of the class.
+ * The fully qualified class name.
*
* @var string
*/
protected $className;
/**
+ * The short class name.
+ *
+ * @var string
+ */
+ protected $shortClassName;
+
+ /**
* TRUE if the caller only wants class annotations.
*
* @var boolean.
@@ -104,9 +111,15 @@ class StaticReflectionParser implements ReflectionProviderInterface
public function __construct($className, $finder, $classAnnotationOptimize = false)
{
$this->className = ltrim($className, '\\');
- if ($lastNsPos = strrpos($this->className, '\\')) {
+ $lastNsPos = strrpos($this->className, '\\');
+
+ if ($lastNsPos !== false) {
$this->namespace = substr($this->className, 0, $lastNsPos);
+ $this->shortClassName = substr($this->className, $lastNsPos + 1);
+ } else {
+ $this->shortClassName = $this->className;
}
+
$this->finder = $finder;
$this->classAnnotationOptimize = $classAnnotationOptimize;
}
@@ -119,7 +132,7 @@ protected function parse()
$this->parsed = true;
$contents = file_get_contents($fileName);
if ($this->classAnnotationOptimize) {
- if (preg_match("/(\A.*)^\s+(abstract|final)?\s+class\s+{$this->className}\s+{/sm", $contents, $matches)) {
+ if (preg_match("/(\A.*)^\s+(abstract|final)?\s+class\s+{$this->shortClassName}\s+{/sm", $contents, $matches)) {
$contents = $matches[1];
}
}
View
24 tests/Doctrine/Tests/Common/Reflection/PR246Test.php
@@ -1,24 +0,0 @@
-<?php
-
-use Doctrine\Common\Reflection\StaticReflectionParser;
-use Doctrine\Common\Reflection\ClassFinderInterface;
-
-class PR246Test extends \PHPUnit_Framework_TestCase
-{
- public function testUndefinedVariable()
- {
- $parser = new StaticReflectionParser(__CLASS__, new PR246FindFile(), true);
- $parser->getDocComment();
- }
-}
-
-class PR246FindFile implements ClassFinderInterface
-{
- /**
- * {@inheritdoc}
- */
- public function findFile($class)
- {
- return __FILE__;
- }
-}
View
30 tests/Doctrine/Tests/Common/Reflection/StaticReflectionParserTest.php
@@ -8,38 +8,56 @@
class StaticReflectionParserTest extends DoctrineTestCase
{
- public function testParentClass()
+ /**
+ * @dataProvider classAnnotationOptimize
+ *
+ * @param bool $classAnnotationOptimize
+ *
+ * @return void
+ */
+ public function testParentClass($classAnnotationOptimize)
{
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
$paths = array(
'Doctrine\\Tests' => array($testsRoot),
);
$noParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\NoParent';
- $staticReflectionParser = new StaticReflectionParser($noParentClassName, new Psr0FindFile($paths));
+ $staticReflectionParser = new StaticReflectionParser($noParentClassName, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
$this->assertEquals($noParentClassName, $declaringClassName);
$className = 'Doctrine\\Tests\\Common\\Reflection\\FullyClassifiedParent';
- $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths));
+ $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
$this->assertEquals($noParentClassName, $declaringClassName);
$className = 'Doctrine\\Tests\\Common\\Reflection\\SameNamespaceParent';
- $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths));
+ $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
$this->assertEquals($noParentClassName, $declaringClassName);
$dummyParentClassName = 'Doctrine\\Tests\\Common\\Reflection\\Dummies\\NoParent';
$className = 'Doctrine\\Tests\\Common\\Reflection\\DeeperNamespaceParent';
- $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths));
+ $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
$this->assertEquals($dummyParentClassName, $declaringClassName);
$className = 'Doctrine\\Tests\\Common\\Reflection\\UseParent';
- $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths));
+ $staticReflectionParser = new StaticReflectionParser($className, new Psr0FindFile($paths), $classAnnotationOptimize);
$declaringClassName = $staticReflectionParser->getStaticReflectionParserForDeclaringClass('property', 'test')->getClassName();
$this->assertEquals($dummyParentClassName, $declaringClassName);
}
+
+ /**
+ * @return array
+ */
+ public function classAnnotationOptimize()
+ {
+ return array(
+ array(false),
+ array(true)
+ );
+ }
}

0 comments on commit 81f97bb

Please sign in to comment.