Permalink
Browse files

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

  • Loading branch information...
beberlei committed May 27, 2012
1 parent 8e644e1 commit 1f2ce21b5613d0cc2500946afc9553e514314c34
View
@@ -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.
@@ -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)) {
@@ -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.");
@@ -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());
@@ -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());
}

0 comments on commit 1f2ce21

Please sign in to comment.