Skip to content

Commit

Permalink
[DDC-1497] Change EntityGenerator add method generation for collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed May 27, 2012
1 parent 8e644e1 commit 1f2ce21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 6 additions & 0 deletions UPGRADE_TO_2_3
@@ -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.
9 changes: 3 additions & 6 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Expand Up @@ -873,12 +873,9 @@ private function generateEntityFieldMappingProperties(ClassMetadataInfo $metadat

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)) {
Expand Down
5 changes: 2 additions & 3 deletions tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Expand Up @@ -115,7 +115,6 @@ public function testGeneratedEntityClass()
$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.");
Expand All @@ -124,7 +123,7 @@ public function testGeneratedEntityClass()
$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());

Expand All @@ -136,7 +135,7 @@ public function testGeneratedEntityClass()
$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());
}
Expand Down

0 comments on commit 1f2ce21

Please sign in to comment.