1
0
mirror of synced 2025-02-22 15:13:13 +03:00

Merge branch 'NewAnnotations'

This commit is contained in:
Benjamin Eberlei 2011-05-25 00:26:29 +02:00
commit 2b3d0a209c
9 changed files with 58 additions and 26 deletions

View File

@ -20,7 +20,8 @@
namespace Doctrine\ORM; namespace Doctrine\ORM;
use Doctrine\Common\Cache\Cache, 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. * Configuration container for all configuration options of Doctrine.
@ -120,9 +121,18 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function newDefaultAnnotationDriver($paths = array()) public function newDefaultAnnotationDriver($paths = array())
{ {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(); if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); $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); return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths);
} }

@ -1 +1 @@
Subproject commit ea434bbea37e067aa52272816c6dcda5ff826154 Subproject commit f87ee1be5113a4a594827731dd1f5647cfc288fc

View File

@ -78,7 +78,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
$config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyDir(__DIR__ . '/../Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies');
$config->setMetadataDriverImpl(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::create()); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
} }
if (is_null($eventManager)) { if (is_null($eventManager)) {
$eventManager = new \Doctrine\Common\EventManager(); $eventManager = new \Doctrine\Common\EventManager();

View File

@ -99,10 +99,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
protected function _loadDriver() protected function _loadDriver()
{ {
$cache = new \Doctrine\Common\Cache\ArrayCache(); return $this->createAnnotationDriver();
$reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
} }
protected function _ensureIsLoaded($entityClassName) protected function _ensureIsLoaded($entityClassName)

View File

@ -67,10 +67,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
{ {
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache); $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/'));
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
$metadataDriver->addPaths(array(__DIR__ . '/../../Models/Global/'));
$entityManager = $this->_createEntityManager($metadataDriver); $entityManager = $this->_createEntityManager($metadataDriver);

View File

@ -82,11 +82,8 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase
*/ */
public function testIsTransient() public function testIsTransient()
{ {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$chain = new DriverChain(); $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->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
$this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient"); $this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");

View File

@ -166,9 +166,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$book = $this->newInstance($metadata); $book = $this->newInstance($metadata);
$cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
$reader = new \Doctrine\Common\Annotations\AnnotationReader(); $driver = $this->createAnnotationDriver();
$reader->setDefaultAnnotationNamespace("Doctrine\\ORM\\Mapping\\");
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
$driver->loadMetadataForClass($cm->name, $cm); $driver->loadMetadataForClass($cm->name, $cm);
$this->assertEquals($cm->columnNames, $metadata->columnNames); $this->assertEquals($cm->columnNames, $metadata->columnNames);
@ -188,9 +186,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$book = $this->newInstance($metadata); $book = $this->newInstance($metadata);
$cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name);
$reader = new \Doctrine\Common\Annotations\AnnotationReader(); $driver = $this->createAnnotationDriver(array(), 'orm');
$reader->setAnnotationNamespaceAlias("Doctrine\\ORM\\Mapping\\", "orm");
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
$driver->loadMetadataForClass($cm->name, $cm); $driver->loadMetadataForClass($cm->name, $cm);
$this->assertEquals($cm->columnNames, $metadata->columnNames); $this->assertEquals($cm->columnNames, $metadata->columnNames);

View File

@ -78,7 +78,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
$class = 'Doctrine\ORM\Mapping\Driver\\' . $driverName; $class = 'Doctrine\ORM\Mapping\Driver\\' . $driverName;
if ($type === 'annotation') { if ($type === 'annotation') {
$driver = $class::create($path); $driver = $this->createAnnotationDriver(array($path));
} else { } else {
$driver = new $class($path); $driver = new $class($path);
} }

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests; namespace Doctrine\Tests;
use Doctrine\Common\Cache\ArrayCache;
/** /**
* Base testcase class for all ORM testcases. * 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). */ /** The query cache that is shared between all ORM tests (except functional tests). */
private static $_queryCacheImpl = null; 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. * Creates an EntityManager for testing purposes.
* *