[2.0] DDC-318 - Fixed idempotency issues with AnnotationDriver::getAllClassNames() even across multiple instances using the same metadata paths.
This commit is contained in:
parent
b25d5d277d
commit
1ddebef8a4
@ -431,7 +431,7 @@ class AnnotationDriver implements Driver
|
|||||||
$classes = array();
|
$classes = array();
|
||||||
|
|
||||||
if ($this->_paths) {
|
if ($this->_paths) {
|
||||||
$declared = get_declared_classes();
|
$includedFiles = array();
|
||||||
|
|
||||||
foreach ((array) $this->_paths as $path) {
|
foreach ((array) $this->_paths as $path) {
|
||||||
if ( ! is_dir($path)) {
|
if ( ! is_dir($path)) {
|
||||||
@ -448,14 +448,18 @@ class AnnotationDriver implements Driver
|
|||||||
continue;
|
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) {
|
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;
|
$classes[] = $className;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,68 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
|||||||
$this->assertEquals('string', $cm->fieldMappings['id']['type']);
|
$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()
|
protected function _loadDriver()
|
||||||
{
|
{
|
||||||
@ -44,6 +106,11 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
|||||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||||
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function _ensureIsLoaded($entityClassName)
|
||||||
|
{
|
||||||
|
new $entityClassName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user