From 3f942e05f36ced89d9108e27b30b053737a49aab Mon Sep 17 00:00:00 2001 From: Vitali Date: Sun, 20 Nov 2011 15:35:58 +0300 Subject: [PATCH 01/18] Register annotations to make ClassMetadataFactoryTest pass alone --- tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 3 ++- tests/Doctrine/Tests/OrmTestCase.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 00b8f5f16..4972f202d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -67,7 +67,8 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - + \Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); + $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); $entityManager = $this->_createEntityManager($metadataDriver); diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 2a7b37dc9..ebf77dead 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -17,7 +17,7 @@ abstract class OrmTestCase extends DoctrineTestCase /** * @param array $paths - * @return \Doctrine\Common\Annotations\AnnotationReader + * @return \Doctrine\ORM\Mapping\Driver\AnnotationDriver */ protected function createAnnotationDriver($paths = array(), $alias = null) { From ffc722a3342c613bd590b8a87dec7ceb8883bc5c Mon Sep 17 00:00:00 2001 From: Vitali Date: Sun, 20 Nov 2011 16:15:40 +0300 Subject: [PATCH 02/18] Allow loading of custom ID generator class by FQN in @GeneratedValue(type=) --- .../ORM/Mapping/ClassMetadataFactory.php | 6 ++- .../ORM/Mapping/ClassMetadataFactoryTest.php | 47 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9bc3ca054..1b7dbf5be 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -505,7 +505,11 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface throw new ORMException("TableGenerator not yet implemented."); break; default: - throw new ORMException("Unknown generator type: " . $class->generatorType); + if (class_exists($class->generatorType)) { + $class->setIdGenerator(new $class->generatorType); + } else { + throw new ORMException("Unknown generator type: " . $class->generatorType); + } } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 4972f202d..ea38eabcd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -64,10 +64,40 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); } + public function testGetMetadataFor_ReturnLoadedCustomIdGenerator() { + $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $cm1->setIdGeneratorType("Doctrine\Tests\ORM\Mapping\CustomIdGenerator"); + $cmf = $this->_createTestFactory(); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + + $actual = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + + $this->assertEquals("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", + $actual->generatorType); + $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", + $actual->idGenerator); + /** + * @GeneratedValue(type=@CustomIdGenerator(table="test")) + */ + } + + public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() { + $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $cm1->setIdGeneratorType("NotExistingIdGenerator"); + $cmf = $this->_createTestFactory(); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + $this->setExpectedException("Doctrine\ORM\ORMException"); + + $actual = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + } + public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - \Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); + AnnotationRegistry::registerFile(__DIR__ . + '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); @@ -142,6 +172,17 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase return EntityManagerMock::create($conn, $config, $eventManager); } + + /** + * @return ClassMetadataFactoryTestSubject + */ + protected function _createTestFactory() { + $mockDriver = new MetadataDriverMock(); + $entityManager = $this->_createEntityManager($mockDriver); + $cmf = new ClassMetadataFactoryTestSubject(); + $cmf->setEntityManager($entityManager); + return $cmf; + } } /* Test subject class with overriden factory method for mocking purposes */ @@ -178,3 +219,7 @@ class TestEntity1 private $other; private $association; } + +class CustomIdGenerator extends \Doctrine\ORM\Id\AbstractIdGenerator { + public function generate(\Doctrine\ORM\EntityManager $em, $entity) {} +} From cd0915deb57c7179dfefde152bfb66f270ec1aba Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 23 Nov 2011 13:06:34 +0300 Subject: [PATCH 03/18] Introcude ClassMetadataInfo::GENERATOR_TYPE_CUSTOM for custom generators to follow current implementation --- .../ORM/Mapping/ClassMetadataFactory.php | 14 ++-- .../ORM/Mapping/ClassMetadataInfo.php | 4 ++ .../ORM/Mapping/ClassMetadataFactoryTest.php | 72 ++++++++++--------- 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 1b7dbf5be..4d93badad 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -504,12 +504,18 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface case ClassMetadata::GENERATOR_TYPE_TABLE: throw new ORMException("TableGenerator not yet implemented."); break; - default: - if (class_exists($class->generatorType)) { - $class->setIdGenerator(new $class->generatorType); + case ClassMetadata::GENERATOR_TYPE_CUSTOM: + $definition = $class->customGeneratorDefinition; + if (class_exists($definition['class'])) { + $class->setIdGenerator(new $definition['class']); } else { - throw new ORMException("Unknown generator type: " . $class->generatorType); + throw new ORMException("Can't find custom generator class: " . + $definition['class']); } + break; + default: + throw new ORMException("Unknown generator type: " . $class->generatorType); + } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 1f54a095b..56eaaa606 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -94,6 +94,10 @@ class ClassMetadataInfo implements ClassMetadata * must have a natural, manually assigned id. */ const GENERATOR_TYPE_NONE = 5; + /** + * CUSTOM means that customer will use own ID generator that supposedly work + */ + const GENERATOR_TYPE_CUSTOM = 6; /** * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time * by doing a property-by-property comparison with the original data. This will diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index ea38eabcd..91f94aa75 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -25,27 +25,12 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $mockPlatform->setPrefersSequences(true); $mockPlatform->setPrefersIdentityColumns(false); - // Self-made metadata - $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); - $cm1->setPrimaryTable(array('name' => '`group`')); - // Add a mapped field - $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); - // Add a mapped field - $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); - // and a mapped association - $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); - // and an association on the owning side - $joinColumns = array( - array('name' => 'other_id', 'referencedColumnName' => 'id') - ); - $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'Other', 'joinColumns' => $joinColumns)); - // and an id generator type - $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); + $cm1 = $this->_createValidClassMetadata(); // SUT $cmf = new ClassMetadataFactoryTestSubject(); $cmf->setEntityManager($entityManager); - $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + $cmf->setMetadataForClass($cm1->name, $cm1); // Prechecks $this->assertEquals(array(), $cm1->parentClasses); @@ -55,7 +40,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType); // Go - $cm1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1 = $cmf->getMetadataFor($cm1->name); $this->assertEquals('group', $cm1->table['name']); $this->assertTrue($cm1->table['quoted']); @@ -64,33 +49,31 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); } - public function testGetMetadataFor_ReturnLoadedCustomIdGenerator() { - $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); - $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); - $cm1->setIdGeneratorType("Doctrine\Tests\ORM\Mapping\CustomIdGenerator"); + public function testGetMetadataFor_ReturnsLoadedCustomIdGenerator() { + $cm1 = $this->_createValidClassMetadata(); + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); + $cm1->customGeneratorDefinition = array( + "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator"); $cmf = $this->_createTestFactory(); - $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + $cmf->setMetadataForClass($cm1->name, $cm1); - $actual = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $actual = $cmf->getMetadataFor($cm1->name); - $this->assertEquals("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $actual->generatorType); $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", $actual->idGenerator); - /** - * @GeneratedValue(type=@CustomIdGenerator(table="test")) - */ } public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() { - $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); - $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); - $cm1->setIdGeneratorType("NotExistingIdGenerator"); + $cm1 = $this->_createValidClassMetadata(); + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); + $cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator"); $cmf = $this->_createTestFactory(); - $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + $cmf->setMetadataForClass($cm1->name, $cm1); $this->setExpectedException("Doctrine\ORM\ORMException"); - $actual = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $actual = $cmf->getMetadataFor($cm1->name); } public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() @@ -183,6 +166,29 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cmf->setEntityManager($entityManager); return $cmf; } + + /** + * @param string $class + * @return ClassMetadata + */ + protected function _createValidClassMetadata() { + $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1->setPrimaryTable(array('name' => '`group`')); + // Add a mapped field + $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); + // Add a mapped field + $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + // and a mapped association + $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); + // and an association on the owning side + $joinColumns = array( + array('name' => 'other_id', 'referencedColumnName' => 'id') + ); + $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'Other', 'joinColumns' => $joinColumns)); + // and an id generator type + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); + return $cm1; + } } /* Test subject class with overriden factory method for mocking purposes */ From 82daf651fbf51765b8cee7dc81a3f4d95b00ebbc Mon Sep 17 00:00:00 2001 From: Vitali Date: Wed, 23 Nov 2011 13:51:45 +0300 Subject: [PATCH 04/18] Pass specified arguments to generator's constructor --- .../ORM/Mapping/ClassMetadataFactory.php | 12 ++++--- .../ORM/Mapping/ClassMetadataInfo.php | 17 ++++++++++ .../ORM/Mapping/ClassMetadataFactoryTest.php | 33 ++++++++++++++++++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 4d93badad..51b6339aa 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -506,10 +506,14 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface break; case ClassMetadata::GENERATOR_TYPE_CUSTOM: $definition = $class->customGeneratorDefinition; - if (class_exists($definition['class'])) { - $class->setIdGenerator(new $definition['class']); - } else { - throw new ORMException("Can't find custom generator class: " . + try { + $reflection = new \ReflectionClass($definition['class']); + $args = isset($definition['args']) ? + $definition['args'] : array(); + $generator = $reflection->newInstanceArgs($args); + $class->setIdGenerator($generator); + } catch (ReflectionException $e) { + throw new ORMException("Can't instantiate custom generator : " . $definition['class']); } break; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 56eaaa606..2f78d18a1 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -180,6 +180,23 @@ class ClassMetadataInfo implements ClassMetadata */ public $rootEntityName; + /** + * READ-ONLY: The definition of custom generator. Only used for CUSTOM + * generator type + * + * The definition has the following structure: + * + * array( + * 'class' => 'ClassName', + * 'args' => array("constructor", "arguments") + * ) + * + * + * @var array + * @todo Merge with tableGeneratorDefinition into generic generatorDefinition + */ + public $customGeneratorDefinition; + /** * The name of the custom repository class used for the entity class. * (Optional). diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 91f94aa75..a5d12f199 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -61,10 +61,27 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $actual->generatorType); - $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", + $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", $actual->idGenerator); } + public function testGetMetadataFor_PasesArgumentsToGeneratorsConstructor() { + $cm1 = $this->_createValidClassMetadata(); + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); + $cm1->customGeneratorDefinition = array( + "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator", + "args" => array("parameter")); + $cmf = $this->_createTestFactory(); + $cmf->setMetadataForClass($cm1->name, $cm1); + $expected = new CustomIdGenerator("parameter"); + + $actual = $cmf->getMetadataFor($cm1->name); + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, + $actual->generatorType); + $this->assertEquals($expected, $actual->idGenerator); + } + public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); @@ -75,6 +92,16 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $actual = $cmf->getMetadataFor($cm1->name); } + + public function testGetMetadataFor_ThrowsExceptionOnMissingCustomGeneratorDefinition() { + $cm1 = $this->_createValidClassMetadata(); + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); + $cmf = $this->_createTestFactory(); + $cmf->setMetadataForClass($cm1->name, $cm1); + $this->setExpectedException("Doctrine\ORM\ORMException"); + + $actual = $cmf->getMetadataFor($cm1->name); + } public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { @@ -227,5 +254,9 @@ class TestEntity1 } class CustomIdGenerator extends \Doctrine\ORM\Id\AbstractIdGenerator { + public $parameter; + public function __construct($parameter = null) { + $this->parameter = $parameter; + } public function generate(\Doctrine\ORM\EntityManager $em, $entity) {} } From 955497e3d56e0759e61f2ce3e9568c3acaf18465 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Thu, 24 Nov 2011 15:27:15 +0300 Subject: [PATCH 05/18] Remove unnecessary mock --- tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index a5d12f199..6224121d0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Tests\Mocks\MetadataDriverMock; -use Doctrine\Tests\Mocks\DatabasePlatformMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; From 48b6356e53d1611fd44c9274e0d843eefd29ffda Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Sat, 26 Nov 2011 11:32:44 +0100 Subject: [PATCH 06/18] Add support for GenerateValue(strategy='CUSTOM') in AnnotationDriver --- .../ORM/Mapping/ClassMetadataInfo.php | 8 +++++ .../ORM/Mapping/Driver/AnnotationDriver.php | 5 +++ .../Mapping/Driver/DoctrineAnnotations.php | 3 +- .../ORM/Mapping/AnnotationDriverTest.php | 31 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 2f78d18a1..99ce88968 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1828,6 +1828,14 @@ class ClassMetadataInfo implements ClassMetadata { $this->idGenerator = $generator; } + + /** + * Sets definition + * @param array $definition + */ + public function setCustomGeneratorDefinition(array $definition) { + $this->customGeneratorDefinition = $definition; + } /** * Sets the definition of the sequence ID generator for this class. diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index d469fd66e..71a46e169 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -319,6 +319,11 @@ class AnnotationDriver implements Driver )); } else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { throw MappingException::tableIdGeneratorNotImplemented($className); + } else if ($customGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { + $metadata->setCustomGeneratorDefinition(array( + 'class' => $customGeneratorAnnot->class, + 'args' => $customGeneratorAnnot->args + )); } } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index 290fc6529..5ed05530f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -39,6 +39,7 @@ require_once __DIR__.'/../UniqueConstraint.php'; require_once __DIR__.'/../Index.php'; require_once __DIR__.'/../JoinTable.php'; require_once __DIR__.'/../SequenceGenerator.php'; +require_once __DIR__.'/../CustomIdGenerator.php'; require_once __DIR__.'/../ChangeTrackingPolicy.php'; require_once __DIR__.'/../OrderBy.php'; require_once __DIR__.'/../NamedQueries.php'; @@ -51,4 +52,4 @@ require_once __DIR__.'/../PostUpdate.php'; require_once __DIR__.'/../PreRemove.php'; require_once __DIR__.'/../PostRemove.php'; require_once __DIR__.'/../PostLoad.php'; -require_once __DIR__.'/../PreFlush.php'; +require_once __DIR__.'/../PreFlush.php'; \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 9273f7c6b..a491fc326 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; +use Doctrine\Common\Annotations\AnnotationRegistry; require_once __DIR__ . '/../../TestInit.php'; @@ -21,6 +22,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $annotationDriver->loadMetadataForClass('stdClass', $cm); } + + public function testLoadMetadataForClassSetsCustomIdGenerator() + { + $cm = new ClassMetadata("Doctrine\Tests\ORM\Mapping\CustomIdGeneratorClass"); + $driver = $this->_loadDriver(); + $expected = array("class" => "\stdClass", + "args" => array("par1", "par2")); + + $driver->loadMetadataForClass( + "Docrtine\Tests\ORM\Mapping\CustomIdGeneratorClass", $cm); + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $cm->generatorType); + $this->assertEquals($expected, $cm->customGeneratorDefinition); + + } /** * @group DDC-268 @@ -99,6 +115,8 @@ class AnnotationDriverTest extends AbstractMappingDriverTest protected function _loadDriver() { + AnnotationRegistry::registerFile(__DIR__ . + '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); return $this->createAnnotationDriver(); } @@ -215,6 +233,19 @@ class AnnotationDriverTest extends AbstractMappingDriverTest } } +/** + * @Entity + */ +class CustomIdGeneratorClass +{ + /** + * @Id @Column + * @GeneratedValue(strategy="CUSTOM") + * @CustomIdGenerator(class="\stdClass", args={"par1", "par2"}) + */ + public $id; +} + /** * @Entity */ From e2953c8cd40909ce119f3ce8c5d85f588f2bdc05 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Sat, 26 Nov 2011 17:45:41 +0100 Subject: [PATCH 07/18] Rename test accoring to what it tests --- tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index a491fc326..a980a13db 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -23,7 +23,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $annotationDriver->loadMetadataForClass('stdClass', $cm); } - public function testLoadMetadataForClassSetsCustomIdGenerator() + public function testLoadMetadataForClassSetsCustomGeneratorDefinition() { $cm = new ClassMetadata("Doctrine\Tests\ORM\Mapping\CustomIdGeneratorClass"); $driver = $this->_loadDriver(); From 6bcfaed6400a26d523065c09b6735ab0388f902e Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Sat, 26 Nov 2011 19:14:47 +0100 Subject: [PATCH 08/18] Remove explicit annotation registration after it was merged into OrmTestCase --- tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php | 3 --- tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 2 -- 2 files changed, 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index a980a13db..51270f73f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; -use Doctrine\Common\Annotations\AnnotationRegistry; require_once __DIR__ . '/../../TestInit.php'; @@ -115,8 +114,6 @@ class AnnotationDriverTest extends AbstractMappingDriverTest protected function _loadDriver() { - AnnotationRegistry::registerFile(__DIR__ . - '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); return $this->createAnnotationDriver(); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 6224121d0..2b21a5b59 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -105,8 +105,6 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - AnnotationRegistry::registerFile(__DIR__ . - '/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); From 2b97f79bd3e67e1357be8e286a4f70be7c310135 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 21:41:54 +0300 Subject: [PATCH 09/18] Add support for custom ID generator in XML --- doctrine-mapping.xsd | 15 +++++++++++++++ lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 ++++++++++ .../ORM/Mapping/AbstractMappingDriverTest.php | 12 ++++++++++++ .../xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 9 +++++++++ 4 files changed, 46 insertions(+) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index e8e21f193..7c9cd2bfe 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -143,6 +143,7 @@ + @@ -253,6 +254,7 @@ + @@ -271,6 +273,19 @@ + + + + + + + + + + + + + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6f655d0db..af783cf4e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -250,6 +250,16 @@ class XmlDriver extends AbstractFileDriver 'allocationSize' => (string)$seqGenerator['allocation-size'], 'initialValue' => (string)$seqGenerator['initial-value'] )); + } else if (isset($idElement->{'custom-generator'})) { + $customGenerator = $idElement->{'custom-generator'}; + $args = array(); + foreach ($customGenerator->args->children() as $argument) { + $args[] = (string) $argument; + } + $metadata->setCustomGeneratorDefinition(array( + 'class' => (string) $customGenerator['class'], + 'args' => $args + )); } else if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7c2887301..407276e5b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -88,6 +88,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $class->sequenceGeneratorDefinition ); } + + public function testEntityCustomGenerator() + { + $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal'); + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, + $class->generatorType, "Generator Type"); + $this->assertEquals( + array("class" => "stdClass", "args" => array("par1", "par2")), + $class->customGeneratorDefinition, + "Custom Generator Definition"); + } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index 6c2a2356f..4f7e6d26f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -8,5 +8,14 @@ + + + + + par1 + par2 + + + \ No newline at end of file From 0a4fbc977036ad708e3054f1df2cbc518d6af4d1 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 21:54:54 +0300 Subject: [PATCH 10/18] Remove test for custom ID generator from AnnotationDriverTest as it duplicates one in AbstractMappingDriverTest --- .../ORM/Mapping/AbstractMappingDriverTest.php | 3 +- .../ORM/Mapping/AnnotationDriverTest.php | 28 ------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 407276e5b..0b128710a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -583,7 +583,8 @@ class User abstract class Animal { /** - * @Id @Column(type="string") @GeneratedValue + * @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM") + * @CustomIdGenerator(class="stdClass", args={"par1", "par2"}) */ public $id; diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 51270f73f..9273f7c6b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -21,21 +21,6 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $annotationDriver->loadMetadataForClass('stdClass', $cm); } - - public function testLoadMetadataForClassSetsCustomGeneratorDefinition() - { - $cm = new ClassMetadata("Doctrine\Tests\ORM\Mapping\CustomIdGeneratorClass"); - $driver = $this->_loadDriver(); - $expected = array("class" => "\stdClass", - "args" => array("par1", "par2")); - - $driver->loadMetadataForClass( - "Docrtine\Tests\ORM\Mapping\CustomIdGeneratorClass", $cm); - - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $cm->generatorType); - $this->assertEquals($expected, $cm->customGeneratorDefinition); - - } /** * @group DDC-268 @@ -230,19 +215,6 @@ class AnnotationDriverTest extends AbstractMappingDriverTest } } -/** - * @Entity - */ -class CustomIdGeneratorClass -{ - /** - * @Id @Column - * @GeneratedValue(strategy="CUSTOM") - * @CustomIdGenerator(class="\stdClass", args={"par1", "par2"}) - */ - public $id; -} - /** * @Entity */ From 84086915e461cf3c97fa1fec998daae3f7f25c3d Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 22:01:55 +0300 Subject: [PATCH 11/18] Add support for custom ID generator in Yaml driver --- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 6 ++++++ .../yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a33c19b6b..8f61920c1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -191,6 +191,12 @@ class YamlDriver extends AbstractFileDriver // Check for SequenceGenerator/TableGenerator definition if (isset($idElement['sequenceGenerator'])) { $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']); + } else if (isset($idElement['customIdGenerator'])) { + $customGenerator = $idElement['customIdGenerator']; + $metadata->setCustomGeneratorDefinition(array( + 'class' => (string) $customGenerator['class'], + 'args' => $customGenerator['args'] + )); } else if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml index cd6ec292c..4f01be63b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml @@ -3,4 +3,12 @@ Doctrine\Tests\ORM\Mapping\Animal: inheritanceType: SINGLE_TABLE discriminatorMap: cat: Cat - dog: Dog \ No newline at end of file + dog: Dog + id: + id: + type: integer + generator: + strategy: CUSTOM + customIdGenerator: + class: stdClass + args: [ par1, par2 ] \ No newline at end of file From 9d1402e4a5035ad2483b794859b84834e185d8d0 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 23:21:46 +0300 Subject: [PATCH 12/18] Fix PHPMappingDriver tests --- .../ORM/Mapping/AbstractMappingDriverTest.php | 3 ++- .../Tests/ORM/Mapping/PHPMappingDriverTest.php | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 0b128710a..1b5191039 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -590,7 +590,8 @@ abstract class Animal public static function loadMetadata(ClassMetadataInfo $metadata) { - + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); + $metadata->setCustomGeneratorDefinition(array("class" => "stdClass", "args" => array("par1", "par2"))); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php index b346973cf..e14828e00 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php @@ -14,17 +14,14 @@ class PHPMappingDriverTest extends AbstractMappingDriverTest { $path = __DIR__ . DIRECTORY_SEPARATOR . 'php'; - /* - // Convert YAML mapping information to PHP - // Uncomment this code if the YAML changes and you want to update the PHP code + // Convert Annotation mapping information to PHP + // Uncomment this code if annotations changed and you want to update the PHP code // for the same mapping information - $cme = new ClassMetadataExporter(); - $cme->addMappingSource(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); - - $exporter = $cme->getExporter('php', $path); - $exporter->setMetadatas($cme->getMetadatas()); - $exporter->export(); - */ +// $meta = new \Doctrine\ORM\Mapping\ClassMetadataInfo("Doctrine\Tests\ORM\Mapping\Animal"); +// $driver = $this->createAnnotationDriver(); +// $driver->loadMetadataForClass("Doctrine\Tests\ORM\Mapping\Animal", $meta); +// $exporter = $cme->getExporter('php', $path); +// echo $exporter->exportClassMetadata($meta); return new PHPDriver($path); } From a8787be0bfd53f04424e326c3a1f18d852b5451e Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 23:31:06 +0300 Subject: [PATCH 13/18] Add missing files from last comming and newly required one after rebase --- .../ORM/Mapping/CustomIdGenerator.php | 31 +++++++++++++++++++ .../php/Doctrine.Tests.ORM.Mapping.Animal.php | 30 ++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 lib/Doctrine/ORM/Mapping/CustomIdGenerator.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php diff --git a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php new file mode 100644 index 000000000..62d31a20c --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php @@ -0,0 +1,31 @@ +. + */ + +namespace Doctrine\ORM\Mapping; + +/** + * @Annotation + * @Target("PROPERTY") + */ +final class CustomIdGenerator implements Annotation { + /** @var string */ + public $class; + /** @var array */ + public $args; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php new file mode 100644 index 000000000..3ad0a0315 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php @@ -0,0 +1,30 @@ +setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); +$metadata->setDiscriminatorColumn(array( + 'name' => 'dtype', + 'type' => 'string', + 'length' => 255, + 'fieldName' => 'dtype', + )); +$metadata->setDiscriminatorMap(array( + 'cat' => 'Doctrine\\Tests\\ORM\\Mapping\\Cat', + 'dog' => 'Doctrine\\Tests\\ORM\\Mapping\\Dog', + )); +$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); +$metadata->mapField(array( + 'fieldName' => 'id', + 'type' => 'string', + 'length' => NULL, + 'precision' => 0, + 'scale' => 0, + 'nullable' => false, + 'unique' => false, + 'id' => true, + 'columnName' => 'id', + )); +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); +$metadata->setCustomGeneratorDefinition(array("class" => "stdClass", "args" => array("par1", "par2"))); From b72d150d3344bd322757e326ddacf85bae567604 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 23:36:23 +0300 Subject: [PATCH 14/18] Rename custom-generator to custom-id-generator in XML mappint to match name in other mapping types --- doctrine-mapping.xsd | 4 ++-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 4 ++-- .../ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 7c9cd2bfe..5fb261e13 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -254,7 +254,7 @@ - + @@ -274,7 +274,7 @@ - + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index af783cf4e..daa09dc15 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -250,8 +250,8 @@ class XmlDriver extends AbstractFileDriver 'allocationSize' => (string)$seqGenerator['allocation-size'], 'initialValue' => (string)$seqGenerator['initial-value'] )); - } else if (isset($idElement->{'custom-generator'})) { - $customGenerator = $idElement->{'custom-generator'}; + } else if (isset($idElement->{'custom-id-generator'})) { + $customGenerator = $idElement->{'custom-id-generator'}; $args = array(); foreach ($customGenerator->args->children() as $argument) { $args[] = (string) $argument; diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index 4f7e6d26f..3c58d4ad8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -10,12 +10,12 @@ - + par1 par2 - + \ No newline at end of file From c92b78bc069a7508ecd670ae5b781b826a5056c4 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Tue, 29 Nov 2011 00:48:08 +0300 Subject: [PATCH 15/18] Cleanup formatting just a little --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 1 - lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 51b6339aa..c45db2029 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -519,7 +519,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface break; default: throw new ORMException("Unknown generator type: " . $class->generatorType); - } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index 5ed05530f..bd1632b2c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -52,4 +52,4 @@ require_once __DIR__.'/../PostUpdate.php'; require_once __DIR__.'/../PreRemove.php'; require_once __DIR__.'/../PostRemove.php'; require_once __DIR__.'/../PostLoad.php'; -require_once __DIR__.'/../PreFlush.php'; \ No newline at end of file +require_once __DIR__.'/../PreFlush.php'; From 353ba4dfd1045333bf46023a9947fcaa171f2ef0 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Wed, 30 Nov 2011 00:20:00 +0300 Subject: [PATCH 16/18] Remove trailing whitespaces and fix brace locations --- doctrine-mapping.xsd | 2 +- .../ORM/Mapping/ClassMetadataInfo.php | 11 +-- .../ORM/Mapping/CustomIdGenerator.php | 3 +- .../ORM/Mapping/Driver/YamlDriver.php | 10 +-- .../ORM/Mapping/AbstractMappingDriverTest.php | 6 +- .../ORM/Mapping/ClassMetadataFactoryTest.php | 72 +++++++++++-------- 6 files changed, 58 insertions(+), 46 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 5fb261e13..b04e8a87c 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -273,7 +273,7 @@ - + diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 99ce88968..5e13d3dfc 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -181,7 +181,7 @@ class ClassMetadataInfo implements ClassMetadata public $rootEntityName; /** - * READ-ONLY: The definition of custom generator. Only used for CUSTOM + * READ-ONLY: The definition of custom generator. Only used for CUSTOM * generator type * * The definition has the following structure: @@ -1828,12 +1828,13 @@ class ClassMetadataInfo implements ClassMetadata { $this->idGenerator = $generator; } - + /** - * Sets definition - * @param array $definition + * Sets definition + * @param array $definition */ - public function setCustomGeneratorDefinition(array $definition) { + public function setCustomGeneratorDefinition(array $definition) + { $this->customGeneratorDefinition = $definition; } diff --git a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php index 62d31a20c..a4a5d8e35 100644 --- a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php +++ b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php @@ -23,7 +23,8 @@ namespace Doctrine\ORM\Mapping; * @Annotation * @Target("PROPERTY") */ -final class CustomIdGenerator implements Annotation { +final class CustomIdGenerator implements Annotation +{ /** @var string */ public $class; /** @var array */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 8f61920c1..76881cab7 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -192,11 +192,11 @@ class YamlDriver extends AbstractFileDriver if (isset($idElement['sequenceGenerator'])) { $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']); } else if (isset($idElement['customIdGenerator'])) { - $customGenerator = $idElement['customIdGenerator']; - $metadata->setCustomGeneratorDefinition(array( - 'class' => (string) $customGenerator['class'], - 'args' => $customGenerator['args'] - )); + $customGenerator = $idElement['customIdGenerator']; + $metadata->setCustomGeneratorDefinition(array( + 'class' => (string) $customGenerator['class'], + 'args' => $customGenerator['args'] + )); } else if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 1b5191039..e80bca23a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -88,12 +88,12 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $class->sequenceGeneratorDefinition ); } - + public function testEntityCustomGenerator() { $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal'); - - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $class->generatorType, "Generator Type"); $this->assertEquals( array("class" => "stdClass", "args" => array("par1", "par2")), diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 2b21a5b59..a05e7380f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -48,23 +48,25 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); } - public function testGetMetadataFor_ReturnsLoadedCustomIdGenerator() { + public function testGetMetadataFor_ReturnsLoadedCustomIdGenerator() + { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cm1->customGeneratorDefinition = array( "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator"); $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); - + $actual = $cmf->getMetadataFor($cm1->name); - - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $actual->generatorType); $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", $actual->idGenerator); } - - public function testGetMetadataFor_PasesArgumentsToGeneratorsConstructor() { + + public function testGetMetadataFor_PasesArgumentsToGeneratorsConstructor() + { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cm1->customGeneratorDefinition = array( @@ -73,39 +75,41 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); $expected = new CustomIdGenerator("parameter"); - + $actual = $cmf->getMetadataFor($cm1->name); - - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, + + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $actual->generatorType); $this->assertEquals($expected, $actual->idGenerator); } - - public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() { + + public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() + { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator"); $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); $this->setExpectedException("Doctrine\ORM\ORMException"); - + $actual = $cmf->getMetadataFor($cm1->name); } - - public function testGetMetadataFor_ThrowsExceptionOnMissingCustomGeneratorDefinition() { + + public function testGetMetadataFor_ThrowsExceptionOnMissingCustomGeneratorDefinition() + { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); $this->setExpectedException("Doctrine\ORM\ORMException"); - + $actual = $cmf->getMetadataFor($cm1->name); } public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - + $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); $entityManager = $this->_createEntityManager($metadataDriver); @@ -120,7 +124,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertFalse($h2); $this->assertTrue($h1); } - + /** * @group DDC-1512 */ @@ -136,13 +140,13 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) ->will($this->returnValue(false)); - + $em = $this->_createEntityManager($driver); - + $this->assertTrue($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsUser')); $this->assertFalse($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsArticle')); } - + /** * @group DDC-1512 */ @@ -158,10 +162,10 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) ->will($this->returnValue(false)); - + $em = $this->_createEntityManager($driver); $em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); - + $this->assertTrue($em->getMetadataFactory()->isTransient('CMS:CmsUser')); $this->assertFalse($em->getMetadataFactory()->isTransient('CMS:CmsArticle')); } @@ -179,23 +183,25 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase return EntityManagerMock::create($conn, $config, $eventManager); } - + /** - * @return ClassMetadataFactoryTestSubject + * @return ClassMetadataFactoryTestSubject */ - protected function _createTestFactory() { + protected function _createTestFactory() + { $mockDriver = new MetadataDriverMock(); $entityManager = $this->_createEntityManager($mockDriver); $cmf = new ClassMetadataFactoryTestSubject(); $cmf->setEntityManager($entityManager); return $cmf; } - + /** * @param string $class - * @return ClassMetadata + * @return ClassMetadata */ - protected function _createValidClassMetadata() { + protected function _createValidClassMetadata() + { $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); $cm1->setPrimaryTable(array('name' => '`group`')); // Add a mapped field @@ -250,10 +256,14 @@ class TestEntity1 private $association; } -class CustomIdGenerator extends \Doctrine\ORM\Id\AbstractIdGenerator { +class CustomIdGenerator extends \Doctrine\ORM\Id\AbstractIdGenerator +{ public $parameter; - public function __construct($parameter = null) { + public function __construct($parameter = null) + { $this->parameter = $parameter; } - public function generate(\Doctrine\ORM\EntityManager $em, $entity) {} + public function generate(\Doctrine\ORM\EntityManager $em, $entity) + { + } } From b09201ae88719f5536e046b21463417ee3b66c6d Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Sun, 8 Jan 2012 14:55:08 +0300 Subject: [PATCH 17/18] Recover changes in ClassMetadataFactoryTest::_createValidClassMetadata() lost during last merge --- .../Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index b5299e5c3..ae97e34cc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -205,18 +205,19 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase { // Self-made metadata $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm1->setPrimaryTable(array('name' => '`group`')); // Add a mapped field $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); // Add a mapped field $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); // and a mapped association - $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); + $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this')); // and an association on the owning side $joinColumns = array( array('name' => 'other_id', 'referencedColumnName' => 'id') ); - $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'Other', 'joinColumns' => $joinColumns)); + $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns)); // and an id generator type $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); return $cm1; From 53ecedf70ab3105d266e67aec684f8b976c0e8f5 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Sun, 8 Jan 2012 15:20:35 +0300 Subject: [PATCH 18/18] Remove support to pass arguments to custom ID generator's constructor --- doctrine-mapping.xsd | 8 +------ .../ORM/Mapping/ClassMetadataFactory.php | 9 ++------ .../ORM/Mapping/ClassMetadataInfo.php | 1 - .../ORM/Mapping/CustomIdGenerator.php | 2 -- .../ORM/Mapping/Driver/AnnotationDriver.php | 3 +-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 7 +----- .../ORM/Mapping/Driver/YamlDriver.php | 3 +-- .../ORM/Mapping/AbstractMappingDriverTest.php | 6 ++--- .../ORM/Mapping/ClassMetadataFactoryTest.php | 23 ------------------- .../php/Doctrine.Tests.ORM.Mapping.Animal.php | 2 +- .../Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 9 ++------ .../Doctrine.Tests.ORM.Mapping.Animal.dcm.yml | 3 +-- 12 files changed, 13 insertions(+), 63 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index b04e8a87c..e8448539c 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -276,13 +276,7 @@ - - - - - - - + diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index d68af7a14..c4329d417 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -520,16 +520,11 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface break; case ClassMetadata::GENERATOR_TYPE_CUSTOM: $definition = $class->customGeneratorDefinition; - try { - $reflection = new \ReflectionClass($definition['class']); - $args = isset($definition['args']) ? - $definition['args'] : array(); - $generator = $reflection->newInstanceArgs($args); - $class->setIdGenerator($generator); - } catch (ReflectionException $e) { + if (!class_exists($definition['class'])) { throw new ORMException("Can't instantiate custom generator : " . $definition['class']); } + $class->setIdGenerator(new $definition['class']); break; default: throw new ORMException("Unknown generator type: " . $class->generatorType); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index f6053c167..8b457ace2 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -188,7 +188,6 @@ class ClassMetadataInfo implements ClassMetadata * * array( * 'class' => 'ClassName', - * 'args' => array("constructor", "arguments") * ) * * diff --git a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php index a4a5d8e35..4739c3c81 100644 --- a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php +++ b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php @@ -27,6 +27,4 @@ final class CustomIdGenerator implements Annotation { /** @var string */ public $class; - /** @var array */ - public $args; } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 05c949727..11b38756a 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -328,8 +328,7 @@ class AnnotationDriver implements Driver throw MappingException::tableIdGeneratorNotImplemented($className); } else if ($customGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { $metadata->setCustomGeneratorDefinition(array( - 'class' => $customGeneratorAnnot->class, - 'args' => $customGeneratorAnnot->args + 'class' => $customGeneratorAnnot->class )); } } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 094861fe7..86785a58b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -256,13 +256,8 @@ class XmlDriver extends AbstractFileDriver )); } else if (isset($idElement->{'custom-id-generator'})) { $customGenerator = $idElement->{'custom-id-generator'}; - $args = array(); - foreach ($customGenerator->args->children() as $argument) { - $args[] = (string) $argument; - } $metadata->setCustomGeneratorDefinition(array( - 'class' => (string) $customGenerator['class'], - 'args' => $args + 'class' => (string) $customGenerator['class'] )); } else if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 590e95998..b1f98915d 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -198,8 +198,7 @@ class YamlDriver extends AbstractFileDriver } else if (isset($idElement['customIdGenerator'])) { $customGenerator = $idElement['customIdGenerator']; $metadata->setCustomGeneratorDefinition(array( - 'class' => (string) $customGenerator['class'], - 'args' => $customGenerator['args'] + 'class' => (string) $customGenerator['class'] )); } else if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 9c6f07389..5a7ccc453 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -97,7 +97,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $class->generatorType, "Generator Type"); $this->assertEquals( - array("class" => "stdClass", "args" => array("par1", "par2")), + array("class" => "stdClass"), $class->customGeneratorDefinition, "Custom Generator Definition"); } @@ -627,14 +627,14 @@ abstract class Animal { /** * @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM") - * @CustomIdGenerator(class="stdClass", args={"par1", "par2"}) + * @CustomIdGenerator(class="stdClass") */ public $id; public static function loadMetadata(ClassMetadataInfo $metadata) { $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); - $metadata->setCustomGeneratorDefinition(array("class" => "stdClass", "args" => array("par1", "par2"))); + $metadata->setCustomGeneratorDefinition(array("class" => "stdClass")); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index ae97e34cc..04f413c95 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -66,24 +66,6 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $actual->idGenerator); } - public function testGetMetadataFor_PasesArgumentsToGeneratorsConstructor() - { - $cm1 = $this->_createValidClassMetadata(); - $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); - $cm1->customGeneratorDefinition = array( - "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator", - "args" => array("parameter")); - $cmf = $this->_createTestFactory(); - $cmf->setMetadataForClass($cm1->name, $cm1); - $expected = new CustomIdGenerator("parameter"); - - $actual = $cmf->getMetadataFor($cm1->name); - - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, - $actual->generatorType); - $this->assertEquals($expected, $actual->idGenerator); - } - public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() { $cm1 = $this->_createValidClassMetadata(); @@ -261,11 +243,6 @@ class TestEntity1 class CustomIdGenerator extends \Doctrine\ORM\Id\AbstractIdGenerator { - public $parameter; - public function __construct($parameter = null) - { - $this->parameter = $parameter; - } public function generate(\Doctrine\ORM\EntityManager $em, $entity) { } diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php index 3ad0a0315..005178eed 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php @@ -27,4 +27,4 @@ $metadata->mapField(array( 'columnName' => 'id', )); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); -$metadata->setCustomGeneratorDefinition(array("class" => "stdClass", "args" => array("par1", "par2"))); +$metadata->setCustomGeneratorDefinition(array("class" => "stdClass")); diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index 3c58d4ad8..6981d0ba6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -9,13 +9,8 @@ - - - - par1 - par2 - - + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml index 4f01be63b..8fdfe3076 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Animal.dcm.yml @@ -10,5 +10,4 @@ Doctrine\Tests\ORM\Mapping\Animal: generator: strategy: CUSTOM customIdGenerator: - class: stdClass - args: [ par1, par2 ] \ No newline at end of file + class: stdClass \ No newline at end of file