Make ORM forward compatible with new Doctrine Annotations library version 2.1
This commit is contained in:
parent
0bb0937372
commit
6d724ad9ff
@ -20,7 +20,8 @@
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\Cache\Cache,
|
||||
Doctrine\ORM\Mapping\Driver\Driver;
|
||||
Doctrine\ORM\Mapping\Driver\Driver,
|
||||
Doctrine\Common\Cache\ArrayCache;
|
||||
|
||||
/**
|
||||
* Configuration container for all configuration options of Doctrine.
|
||||
@ -120,9 +121,18 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*/
|
||||
public function newDefaultAnnotationDriver($paths = array())
|
||||
{
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
|
||||
if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
$reader->setIgnoreNotImportedAnnotations(true);
|
||||
$reader->setEnableParsePhpImports(false);
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader(
|
||||
new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
|
||||
);
|
||||
} else {
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
}
|
||||
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths);
|
||||
}
|
||||
|
||||
|
2
lib/vendor/doctrine-common
vendored
2
lib/vendor/doctrine-common
vendored
@ -1 +1 @@
|
||||
Subproject commit ea434bbea37e067aa52272816c6dcda5ff826154
|
||||
Subproject commit f87ee1be5113a4a594827731dd1f5647cfc288fc
|
@ -78,7 +78,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager
|
||||
$config = new \Doctrine\ORM\Configuration();
|
||||
$config->setProxyDir(__DIR__ . '/../Proxies');
|
||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||
$config->setMetadataDriverImpl(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::create());
|
||||
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
|
||||
}
|
||||
if (is_null($eventManager)) {
|
||||
$eventManager = new \Doctrine\Common\EventManager();
|
||||
|
@ -99,10 +99,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
||||
|
||||
protected function _loadDriver()
|
||||
{
|
||||
$cache = new \Doctrine\Common\Cache\ArrayCache();
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||
return $this->createAnnotationDriver();
|
||||
}
|
||||
|
||||
protected function _ensureIsLoaded($entityClassName)
|
||||
|
@ -67,10 +67,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
$metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||
$metadataDriver->addPaths(array(__DIR__ . '/../../Models/Global/'));
|
||||
$metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/'));
|
||||
|
||||
$entityManager = $this->_createEntityManager($metadataDriver);
|
||||
|
||||
|
@ -81,12 +81,9 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
||||
* @group DDC-706
|
||||
*/
|
||||
public function testIsTransient()
|
||||
{
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
|
||||
{
|
||||
$chain = new DriverChain();
|
||||
$chain->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array()), 'Doctrine\Tests\Models\CMS');
|
||||
$chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS');
|
||||
|
||||
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
|
||||
$this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
|
||||
|
@ -166,9 +166,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$book = $this->newInstance($metadata);
|
||||
|
||||
$cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace("Doctrine\\ORM\\Mapping\\");
|
||||
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||
$driver = $this->createAnnotationDriver();
|
||||
$driver->loadMetadataForClass($cm->name, $cm);
|
||||
|
||||
$this->assertEquals($cm->columnNames, $metadata->columnNames);
|
||||
@ -188,9 +186,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$book = $this->newInstance($metadata);
|
||||
|
||||
$cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setAnnotationNamespaceAlias("Doctrine\\ORM\\Mapping\\", "orm");
|
||||
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||
$driver = $this->createAnnotationDriver(array(), 'orm');
|
||||
$driver->loadMetadataForClass($cm->name, $cm);
|
||||
|
||||
$this->assertEquals($cm->columnNames, $metadata->columnNames);
|
||||
|
@ -78,7 +78,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
|
||||
|
||||
$class = 'Doctrine\ORM\Mapping\Driver\\' . $driverName;
|
||||
if ($type === 'annotation') {
|
||||
$driver = $class::create($path);
|
||||
$driver = $this->createAnnotationDriver(array($path));
|
||||
} else {
|
||||
$driver = new $class($path);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
|
||||
/**
|
||||
* Base testcase class for all ORM testcases.
|
||||
*/
|
||||
@ -12,6 +14,39 @@ abstract class OrmTestCase extends DoctrineTestCase
|
||||
/** The query cache that is shared between all ORM tests (except functional tests). */
|
||||
private static $_queryCacheImpl = null;
|
||||
|
||||
/**
|
||||
* @param array $paths
|
||||
* @return \Doctrine\Common\Annotations\AnnotationReader
|
||||
*/
|
||||
protected function createAnnotationDriver($paths = array(), $alias = null)
|
||||
{
|
||||
if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0', '>=')) {
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader(
|
||||
new \Doctrine\Common\Annotations\AnnotationReader(), new ArrayCache()
|
||||
);
|
||||
} else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setIgnoreNotImportedAnnotations(true);
|
||||
$reader->setEnableParsePhpImports(false);
|
||||
if ($alias) {
|
||||
$reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias);
|
||||
} else {
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
}
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader(
|
||||
new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
|
||||
);
|
||||
} else {
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
if ($alias) {
|
||||
$reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias);
|
||||
} else {
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
}
|
||||
}
|
||||
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EntityManager for testing purposes.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user