Merge pull request #1063 from FlorianLB/master
singularize variable name on add/remove methods for EntityGenerator
This commit is contained in:
commit
381cf8022f
@ -1149,8 +1149,10 @@ public function __construct()
|
||||
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
|
||||
{
|
||||
$methodName = $type . Inflector::classify($fieldName);
|
||||
$variableName = Inflector::camelize($fieldName);
|
||||
if (in_array($type, array("add", "remove"))) {
|
||||
$methodName = Inflector::singularize($methodName);
|
||||
$variableName = Inflector::singularize($variableName);
|
||||
}
|
||||
|
||||
if ($this->hasMethod($methodName, $metadata)) {
|
||||
@ -1171,10 +1173,10 @@ public function __construct()
|
||||
}
|
||||
|
||||
$replacements = array(
|
||||
'<description>' => ucfirst($type) . ' ' . $fieldName,
|
||||
'<description>' => ucfirst($type) . ' ' . $variableName,
|
||||
'<methodTypeHint>' => $methodTypeHint,
|
||||
'<variableType>' => $variableType,
|
||||
'<variableName>' => Inflector::camelize($fieldName),
|
||||
'<variableName>' => $variableName,
|
||||
'<methodName>' => $methodName,
|
||||
'<fieldName>' => $fieldName,
|
||||
'<variableDefault>' => ($defaultValue !== null ) ? (' = '.$defaultValue) : '',
|
||||
|
@ -133,6 +133,14 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$book->setName('Jonathan H. Wage');
|
||||
$this->assertEquals('Jonathan H. Wage', $book->getName());
|
||||
|
||||
$reflMethod = new \ReflectionMethod($metadata->name, 'addComment');
|
||||
$addCommentParameters = $reflMethod->getParameters();
|
||||
$this->assertEquals('comment', $addCommentParameters[0]->getName());
|
||||
|
||||
$reflMethod = new \ReflectionMethod($metadata->name, 'removeComment');
|
||||
$removeCommentParameters = $reflMethod->getParameters();
|
||||
$this->assertEquals('comment', $removeCommentParameters[0]->getName());
|
||||
|
||||
$author = new EntityGeneratorAuthor();
|
||||
$book->setAuthor($author);
|
||||
$this->assertEquals($author, $book->getAuthor());
|
||||
|
Loading…
x
Reference in New Issue
Block a user