1
0
mirror of synced 2024-12-13 14:56:01 +03:00

[2.0] DDC-318 - Fixed idempotency issues with AnnotationDriver::getAllClassNames() even across multiple instances using the same metadata paths.

This commit is contained in:
beberlei 2010-03-18 23:04:21 +00:00
parent b25d5d277d
commit 1ddebef8a4
2 changed files with 77 additions and 6 deletions

View File

@ -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;
}
}
}

View 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;
}
}
/**