1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

[DDC-1497] Change EntityGenerator add method generation for collections.

This commit is contained in:
Benjamin Eberlei 2012-05-27 20:31:01 +02:00
parent 8e644e1303
commit 1f2ce21b56
3 changed files with 11 additions and 9 deletions

View file

@ -1,3 +1,9 @@
# EntityGenerator add*() method generation
When generating an add*() method for a collection the EntityGenerator will now not
use the Type-Hint to get the singular for the collection name, but use the field-name
and strip a trailing "s" character if there is one.
# Merge copies non persisted properties too
When merging an entity in UoW not only mapped properties are copied, but also others.

View file

@ -873,12 +873,9 @@ public function <methodName>()
private function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
if ($type == "add") {
$addMethod = explode("\\", $typeHint);
$addMethod = end($addMethod);
$methodName = $type . $addMethod;
} else {
$methodName = $type . Inflector::classify($fieldName);
$methodName = $type . Inflector::classify($fieldName);
if ($type == "add" && substr($methodName, -1) == "s") {
$methodName = substr($methodName, 0, -1);
}
if ($this->hasMethod($methodName, $metadata)) {

View file

@ -115,7 +115,6 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$metadata = $this->generateBookEntityFixture();
$book = $this->newInstance($metadata);
$this->assertTrue(class_exists($metadata->name), "Class does not exist.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', '__construct'), "EntityGeneratorBook::__construct() missing.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getId'), "EntityGeneratorBook::getId() missing.");
@ -124,7 +123,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'setAuthor'), "EntityGeneratorBook::setAuthor() missing.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getAuthor'), "EntityGeneratorBook::getAuthor() missing.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getComments'), "EntityGeneratorBook::getComments() missing.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'addEntityGeneratorComment'), "EntityGeneratorBook::addEntityGeneratorComment() missing.");
$this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'addComment'), "EntityGeneratorBook::addComment() missing.");
$this->assertEquals('published', $book->getStatus());
@ -136,7 +135,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals($author, $book->getAuthor());
$comment = new EntityGeneratorComment();
$book->addEntityGeneratorComment($comment);
$book->addComment($comment);
$this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments());
$this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array($comment)), $book->getComments());
}