Commit 1ddebef8 authored by beberlei's avatar beberlei

[2.0] DDC-318 - Fixed idempotency issues with...

[2.0] DDC-318 - Fixed idempotency issues with AnnotationDriver::getAllClassNames() even across multiple instances using the same metadata paths.
parent b25d5d27
......@@ -431,7 +431,7 @@ class AnnotationDriver implements Driver
$classes = array();
if ($this->_paths) {
$declared = get_declared_classes();
$includedFiles = array();
foreach ((array) $this->_paths as $path) {
if ( ! is_dir($path)) {
......@@ -447,15 +447,19 @@ class AnnotationDriver implements Driver
if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) {
continue;
}
require_once $file->getPathName();
$sourceFile = realpath($file->getPathName());
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
}
$declared = array_diff(get_declared_classes(), $declared);
$declared = get_declared_classes();
foreach ($declared as $className) {
if ( ! $this->isTransient($className)) {
$rc = new \ReflectionClass($className);
$sourceFile = $rc->getFileName();
if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
$classes[] = $className;
}
}
......@@ -466,4 +470,4 @@ class AnnotationDriver implements Driver
return $classes;
}
}
\ No newline at end of file
}
......@@ -36,6 +36,68 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$this->assertEquals('string', $cm->fieldMappings['id']['type']);
}
/**
* @group DDC-318
*/
public function testGetAllClassNamesIsIdempotent()
{
$annotationDriver = $this->_loadDriverForCMSModels();
$original = $annotationDriver->getAllClassNames();
$annotationDriver = $this->_loadDriverForCMSModels();
$afterTestReset = $annotationDriver->getAllClassNames();
$this->assertEquals($original, $afterTestReset);
}
/**
* @group DDC-318
*/
public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances()
{
$annotationDriver = $this->_loadDriverForCMSModels();
$original = $annotationDriver->getAllClassNames();
$annotationDriver = $this->_loadDriverForCMSModels();
$afterTestReset = $annotationDriver->getAllClassNames();
$this->assertEquals($original, $afterTestReset);
}
/**
* @group DDC-318
*/
public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate()
{
$rightClassName = 'Doctrine\Tests\Models\CMS\CmsUser';
$this->_ensureIsLoaded($rightClassName);
$annotationDriver = $this->_loadDriverForCMSModels();
$classes = $annotationDriver->getAllClassNames();
$this->assertContains($rightClassName, $classes);
}
/**
* @group DDC-318
*/
public function testGetClassNamesReturnsOnlyTheAppropriateClasses()
{
$extraneousClassName = 'Doctrine\Tests\Models\ECommerce\ECommerceCart';
$this->_ensureIsLoaded($extraneousClassName);
$annotationDriver = $this->_loadDriverForCMSModels();
$classes = $annotationDriver->getAllClassNames();
$this->assertNotContains($extraneousClassName, $classes);
}
protected function _loadDriverForCMSModels()
{
$annotationDriver = $this->_loadDriver();
$annotationDriver->addPaths(array(__DIR__ . '/../../Models/CMS/'));
return $annotationDriver;
}
protected function _loadDriver()
{
......@@ -44,6 +106,11 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
}
protected function _ensureIsLoaded($entityClassName)
{
new $entityClassName;
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment