1
0
mirror of synced 2025-02-06 23:39:25 +03:00

[2.0] Improving EntityGenerated: added normal doc blocks above annotations(even if annotations aren't generated), adding type hinting, added generation of default values for properties

This commit is contained in:
jwage 2010-03-19 22:38:45 +00:00
parent b73e3c064c
commit 42c5562874
3 changed files with 295 additions and 223 deletions

View File

@ -194,6 +194,17 @@ abstract class Type
self::$_typesMap[$name] = $className; self::$_typesMap[$name] = $className;
} }
/**
* Get the types array map which holds all registered types and the corresponding
* type class
*
* @return array $typesMap
*/
public static function getTypesMap()
{
return self::$_typesMap;
}
public function __toString() public function __toString()
{ {
$e = explode('\\', get_class($this)); $e = explode('\\', get_class($this));

View File

@ -22,7 +22,8 @@
namespace Doctrine\ORM\Tools; namespace Doctrine\ORM\Tools;
use Doctrine\ORM\Mapping\ClassMetadataInfo, use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\AssociationMapping; Doctrine\ORM\Mapping\AssociationMapping,
Doctrine\Common\Util\Inflector;
/** /**
* Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances * Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances
@ -78,7 +79,7 @@ class EntityGenerator
/** Whether or not to re-generate entity class if it exists already */ /** Whether or not to re-generate entity class if it exists already */
private $_regenerateEntityIfExists = false; private $_regenerateEntityIfExists = false;
private static $_template = private static $_classTemplate =
'<?php '<?php
<namespace><use> <namespace><use>
@ -88,6 +89,48 @@ class EntityGenerator
<entityBody> <entityBody>
}'; }';
private static $_getMethodTemplate =
'/**
* <description>
*
* @return <variableType>$<variableName>
*/
public function <methodName>()
{
return $this-><fieldName>;
}';
private static $_setMethodTemplate =
'/**
* <description>
*
* @param <variableType>$<variableName>
*/
public function <methodName>(<methodTypeHint>$<variableName>)
{
$this-><fieldName> = $<variableName>;
}';
private static $_addMethodTemplate =
'/**
* <description>
*
* @param <variableType>$<variableName>
*/
public function <methodName>(<methodTypeHint>$<variableName>)
{
$this-><fieldName>[] = $<variableName>;
}';
private static $_lifecycleCallbackMethodTemplate =
'/**
* @<name>
*/
public function <methodName>()
{
// Add your code here
}';
/** /**
* Generate and write entity classes for the given array of ClassMetadataInfo instances * Generate and write entity classes for the given array of ClassMetadataInfo instances
* *
@ -153,12 +196,12 @@ class EntityGenerator
$replacements = array( $replacements = array(
$this->_generateEntityNamespace($metadata), $this->_generateEntityNamespace($metadata),
$this->_generateEntityUse($metadata), $this->_generateEntityUse($metadata),
$this->_generateAnnotations ? "\n" . $this->_generateEntityAnnotation($metadata) : null, $this->_generateEntityDocBlock($metadata),
$this->_generateEntityClassName($metadata), $this->_generateEntityClassName($metadata),
$this->_generateEntityBody($metadata) $this->_generateEntityBody($metadata)
); );
$code = str_replace($placeHolders, $replacements, self::$_template); $code = str_replace($placeHolders, $replacements, self::$_classTemplate);
return $code; return $code;
} }
@ -300,7 +343,7 @@ class EntityGenerator
return $code; return $code;
} }
private function _hasProperty($property, $metadata) private function _hasProperty($property, ClassMetadataInfo $metadata)
{ {
if ($this->_isNew) { if ($this->_isNew) {
return false; return false;
@ -309,7 +352,7 @@ class EntityGenerator
} }
} }
private function _hasMethod($method, $metadata) private function _hasMethod($method, ClassMetadataInfo $metadata)
{ {
if ($this->_isNew) { if ($this->_isNew) {
return false; return false;
@ -318,7 +361,7 @@ class EntityGenerator
} }
} }
private function _hasNamespace($metadata) private function _hasNamespace(ClassMetadataInfo $metadata)
{ {
return strpos($metadata->name, '\\') ? true : false; return strpos($metadata->name, '\\') ? true : false;
} }
@ -345,7 +388,7 @@ class EntityGenerator
return $refl->getNamespaceName() ? $refl->getNamespaceName():$refl->getShortName(); return $refl->getNamespaceName() ? $refl->getNamespaceName():$refl->getShortName();
} }
private function _getClassName($metadata) private function _getClassName(ClassMetadataInfo $metadata)
{ {
if ($pos = strrpos($metadata->name, '\\')) { if ($pos = strrpos($metadata->name, '\\')) {
return substr($metadata->name, $pos + 1, strlen($metadata->name)); return substr($metadata->name, $pos + 1, strlen($metadata->name));
@ -354,15 +397,19 @@ class EntityGenerator
} }
} }
private function _getNamespace($metadata) private function _getNamespace(ClassMetadataInfo $metadata)
{ {
return substr($metadata->name, 0, strrpos($metadata->name, '\\')); return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
} }
private function _generateEntityAnnotation($metadata) private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
{ {
$lines = array(); $lines = array();
$lines[] = '/**'; $lines[] = '/**';
$lines[] = ' * '.$metadata->name;
if ($this->_generateAnnotations) {
$lines[] = ' *';
$methods = array( $methods = array(
'_generateTableAnnotation', '_generateTableAnnotation',
@ -390,6 +437,7 @@ class EntityGenerator
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) { if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
$lines[] = ' * @HasLifecycleCallbacks'; $lines[] = ' * @HasLifecycleCallbacks';
} }
}
$lines[] = ' */'; $lines[] = ' */';
@ -448,51 +496,51 @@ class EntityGenerator
foreach ($metadata->fieldMappings as $fieldMapping) { foreach ($metadata->fieldMappings as $fieldMapping) {
if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id']) { if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id']) {
if ($code = $this->_generateEntityStubMethod('set', $fieldMapping['fieldName'], $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) {
$methods[] = $code; $methods[] = $code;
} }
} }
if ($code = $this->_generateEntityStubMethod('get', $fieldMapping['fieldName'], $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) {
$methods[] = $code; $methods[] = $code;
} }
} }
foreach ($metadata->associationMappings as $associationMapping) { foreach ($metadata->associationMappings as $associationMapping) {
if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) { if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) {
if ($code = $this->_generateEntityStubMethod('set', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->_generateEntityStubMethod('get', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) { } else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) {
if ($associationMapping->isOwningSide) { if ($associationMapping->isOwningSide) {
if ($code = $this->_generateEntityStubMethod('set', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->_generateEntityStubMethod('get', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
} else { } else {
if ($code = $this->_generateEntityStubMethod('add', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->_generateEntityStubMethod('get', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, 'Doctrine\Common\Collections\Collection')) {
$methods[] = $code; $methods[] = $code;
} }
} }
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) { } else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) {
if ($code = $this->_generateEntityStubMethod('add', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->_generateEntityStubMethod('get', $associationMapping->sourceFieldName, $metadata)) { if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, 'Doctrine\Common\Collections\Collection')) {
$methods[] = $code; $methods[] = $code;
} }
} }
} }
return implode('', $methods); return implode("\n\n", $methods);
} }
private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
@ -517,9 +565,7 @@ class EntityGenerator
if ($this->_hasProperty($associationMapping->sourceFieldName, $metadata)) { if ($this->_hasProperty($associationMapping->sourceFieldName, $metadata)) {
continue; continue;
} }
if ($this->_generateAnnotations) { $lines[] = $this->_generateAssociationMappingPropertyDocBlock($associationMapping, $metadata);
$lines[] = $this->_generateAssociationMappingAnnotation($associationMapping, $metadata);
}
$lines[] = $this->_spaces . 'private $' . $associationMapping->sourceFieldName . ($associationMapping->isManyToMany() ? ' = array()' : null) . ";\n"; $lines[] = $this->_spaces . 'private $' . $associationMapping->sourceFieldName . ($associationMapping->isManyToMany() ? ' = array()' : null) . ";\n";
} }
$code = implode("\n", $lines); $code = implode("\n", $lines);
@ -533,54 +579,44 @@ class EntityGenerator
if ($this->_hasProperty($fieldMapping['fieldName'], $metadata)) { if ($this->_hasProperty($fieldMapping['fieldName'], $metadata)) {
continue; continue;
} }
if ($this->_generateAnnotations) { $lines[] = $this->_generateFieldMappingPropertyDocBlock($fieldMapping, $metadata);
$lines[] = $this->_generateFieldMappingAnnotation($fieldMapping, $metadata); $lines[] = $this->_spaces . 'private $' . $fieldMapping['fieldName'] . (isset($fieldMapping['default']) ? ' = ' . var_export($fieldMapping['default'], true) : null) . ";\n";
}
$lines[] = $this->_spaces . 'private $' . $fieldMapping['fieldName'] . ";\n";
} }
$code = implode("\n", $lines); $code = implode("\n", $lines);
return $code; return $code;
} }
private function _generateEntityStubMethod($type, $fieldName, ClassMetadataInfo $metadata) private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null)
{ {
$methodName = $type . ucfirst($fieldName); $methodName = $type . Inflector::classify($fieldName);
if ($this->_hasMethod($methodName, $metadata)) { if ($this->_hasMethod($methodName, $metadata)) {
return; return;
} }
$method = array(); $var = sprintf('_%sMethodTemplate', $type);
$method[] = $this->_spaces . '/**'; $template = self::$$var;
if ($type == 'get') {
$method[] = $this->_spaces . ' * Get ' . $fieldName;
} else if ($type == 'set') {
$method[] = $this->_spaces . ' * Set ' . $fieldName;
} else if ($type == 'add') {
$method[] = $this->_spaces . ' * Add ' . $fieldName;
}
$method[] = $this->_spaces . ' */';
if ($type == 'get') { $variableType = $typeHint ? $typeHint . ' ' : null;
$method[] = $this->_spaces . 'public function ' . $methodName . '()';
} else if ($type == 'set') {
$method[] = $this->_spaces . 'public function ' . $methodName . '($value)';
} else if ($type == 'add') {
$method[] = $this->_spaces . 'public function ' . $methodName . '($value)';
}
$method[] = $this->_spaces . '{'; $types = \Doctrine\DBAL\Types\Type::getTypesMap();
if ($type == 'get') { $methodTypeHint = $typeHint && ! isset($types[$typeHint]) ? $typeHint . ' ' : null;
$method[] = $this->_spaces . $this->_spaces . 'return $this->' . $fieldName . ';';
} else if ($type == 'set') {
$method[] = $this->_spaces . $this->_spaces . '$this->' . $fieldName . ' = $value;';
} else if ($type == 'add') {
$method[] = $this->_spaces . $this->_spaces . '$this->' . $fieldName . '[] = $value;';
}
$method[] = $this->_spaces . '}'; $replacements = array(
$method[] = "\n"; '<description>' => ucfirst($type) . ' ' . $fieldName,
'<methodTypeHint>' => $methodTypeHint,
'<variableType>' => $variableType,
'<variableName>' => Inflector::camelize($fieldName),
'<methodName>' => $methodName,
'<fieldName>' => $fieldName
);
return implode("\n", $method); $method = str_replace(
array_keys($replacements),
array_values($replacements),
$template
);
return $this->_prefixCodeWithSpaces($method);
} }
private function _generateLifecycleCallbackMethod($name, $methodName, $metadata) private function _generateLifecycleCallbackMethod($name, $methodName, $metadata)
@ -589,15 +625,17 @@ class EntityGenerator
return; return;
} }
$method = array(); $replacements = array(
$method[] = $this->_spaces . '/**'; '<name>' => $name,
$method[] = $this->_spaces . ' * @'.$name; '<methodName>' => $methodName,
$method[] = $this->_spaces . ' */'; );
$method[] = $this->_spaces . 'public function ' . $methodName . '()';
$method[] = $this->_spaces . '{';
$method[] = $this->_spaces . '}';
return implode("\n", $method)."\n\n"; $method = str_replace(
array_keys($replacements),
array_values($replacements),
self::$_lifecycleCallbackMethodTemplate
);
return $this->_prefixCodeWithSpaces($method);
} }
private function _generateJoinColumnAnnotation(array $joinColumn) private function _generateJoinColumnAnnotation(array $joinColumn)
@ -627,8 +665,15 @@ class EntityGenerator
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')'; return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
} }
private function _generateAssociationMappingAnnotation(AssociationMapping $associationMapping, ClassMetadataInfo $metadata) private function _generateAssociationMappingPropertyDocBlock(AssociationMapping $associationMapping, ClassMetadataInfo $metadata)
{ {
$lines = array();
$lines[] = $this->_spaces . '/**';
$lines[] = $this->_spaces . ' * @var ' . $associationMapping->targetEntityName;
if ($this->_generateAnnotations) {
$lines[] = $this->_spaces . ' *';
$e = explode('\\', get_class($associationMapping)); $e = explode('\\', get_class($associationMapping));
$type = str_replace('Mapping', '', end($e)); $type = str_replace('Mapping', '', end($e));
$typeOptions = array(); $typeOptions = array();
@ -651,8 +696,6 @@ class EntityGenerator
$typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false'); $typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false');
} }
$lines = array();
$lines[] = $this->_spaces . '/**';
$lines[] = $this->_spaces . ' * @' . $type . '(' . implode(', ', $typeOptions) . ')'; $lines[] = $this->_spaces . ' * @' . $type . '(' . implode(', ', $typeOptions) . ')';
if (isset($associationMapping->joinColumns) && $associationMapping->joinColumns) { if (isset($associationMapping->joinColumns) && $associationMapping->joinColumns) {
@ -700,16 +743,21 @@ class EntityGenerator
$lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1); $lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1);
$lines[] = $this->_spaces . ' * })'; $lines[] = $this->_spaces . ' * })';
} }
}
$lines[] = $this->_spaces . ' */'; $lines[] = $this->_spaces . ' */';
return implode("\n", $lines); return implode("\n", $lines);
} }
private function _generateFieldMappingAnnotation(array $fieldMapping, ClassMetadataInfo $metadata) private function _generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
{ {
$lines = array(); $lines = array();
$lines[] = $this->_spaces . '/**'; $lines[] = $this->_spaces . '/**';
$lines[] = $this->_spaces . ' * @var ' . $fieldMapping['type'] . ' $' . $fieldMapping['fieldName'];
if ($this->_generateAnnotations) {
$lines[] = $this->_spaces . ' *';
$column = array(); $column = array();
if (isset($fieldMapping['columnName'])) { if (isset($fieldMapping['columnName'])) {
@ -770,11 +818,22 @@ class EntityGenerator
if (isset($fieldMapping['version']) && $fieldMapping['version']) { if (isset($fieldMapping['version']) && $fieldMapping['version']) {
$lines[] = $this->_spaces . ' * @Version'; $lines[] = $this->_spaces . ' * @Version';
} }
}
$lines[] = $this->_spaces . ' */'; $lines[] = $this->_spaces . ' */';
return implode("\n", $lines); return implode("\n", $lines);
} }
private function _prefixCodeWithSpaces($code, $num = 1)
{
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
$lines[$key] = str_repeat($this->_spaces, $num) . $lines[$key];
}
return implode("\n", $lines);
}
private function _getInheritanceTypeString($type) private function _getInheritanceTypeString($type)
{ {
switch ($type) switch ($type)

View File

@ -26,20 +26,20 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
{ {
$metadata = new ClassMetadataInfo('EntityGeneratorBook'); $metadata = new ClassMetadataInfo('EntityGeneratorBook');
$metadata->primaryTable['name'] = 'book'; $metadata->primaryTable['name'] = 'book';
$metadata->mapField(array('fieldName' => 'name', 'type' => 'varchar')); $metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); $metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', 'mappedBy' => 'book'));
$joinColumns = array( $joinColumns = array(
array('name' => 'other_id', 'referencedColumnName' => 'id') array('name' => 'author_id', 'referencedColumnName' => 'id')
); );
$metadata->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'Other', 'joinColumns' => $joinColumns));
$metadata->mapManyToMany(array( $metadata->mapManyToMany(array(
'fieldName' => 'author', 'fieldName' => 'comments',
'targetEntity' => 'Author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment',
'joinTable' => array( 'joinTable' => array(
'name' => 'book_author', 'name' => 'book_comment',
'joinColumns' => array(array('name' => 'bar_id', 'referencedColumnName' => 'id')), 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')),
'inverseJoinColumns' => array(array('name' => 'baz_id', 'referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')),
), ),
)); ));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
@ -57,45 +57,44 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
* @depends testWriteEntityClass * @depends testWriteEntityClass
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
*/ */
public function testGeneratedEntityClassMethods($metadata) public function testGeneratedEntityClass($metadata)
{ {
$this->assertTrue(method_exists('\EntityGeneratorBook', 'getId')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'getId'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'setName')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'setName'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'getName')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'getName'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'setOther')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'setAuthor'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'getOther'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'setAssociation'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'getAssociation'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'getAuthor')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'getAuthor'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'addAuthor')); $this->assertTrue(method_exists('\EntityGeneratorBook', 'getComments'));
$this->assertTrue(method_exists('\EntityGeneratorBook', 'addComments'));
$book = new \EntityGeneratorBook(); $book = new \EntityGeneratorBook();
$this->assertEquals('published', $book->getStatus());
$book->setName('Jonathan H. Wage'); $book->setName('Jonathan H. Wage');
$this->assertEquals('Jonathan H. Wage', $book->getName()); $this->assertEquals('Jonathan H. Wage', $book->getName());
$book->setOther('Other'); $author = new EntityGeneratorAuthor();
$this->assertEquals('Other', $book->getOther()); $book->setAuthor($author);
$this->assertEquals($author, $book->getAuthor());
$book->setAssociation('Test'); $comment = new EntityGeneratorComment();
$this->assertEquals('Test', $book->getAssociation()); $book->addComments($comment);
$this->assertEquals(array($comment), $book->getComments());
$book->addAuthor('Test');
$this->assertEquals(array('Test'), $book->getAuthor());
return $metadata; return $metadata;
} }
/** /**
* @depends testGeneratedEntityClassMethods * @depends testGeneratedEntityClass
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
*/ */
public function testEntityUpdatingWorks($metadata) public function testEntityUpdatingWorks($metadata)
{ {
$metadata->mapField(array('fieldName' => 'test', 'type' => 'varchar')); $metadata->mapField(array('fieldName' => 'test', 'type' => 'string'));
$this->_generator->writeEntityClass($metadata, __DIR__); $this->_generator->writeEntityClass($metadata, __DIR__);
$code = file_get_contents(__DIR__ . '/EntityGeneratorBook.php'); $code = file_get_contents(__DIR__ . '/EntityGeneratorBook.php');
$this->assertTrue(strstr($code, 'private $test;') !== false); $this->assertTrue(strstr($code, 'private $test;') !== false);
$this->assertTrue(strstr($code, 'private $test;') !== false); $this->assertTrue(strstr($code, 'private $test;') !== false);
$this->assertTrue(strstr($code, 'public function getTest(') !== false); $this->assertTrue(strstr($code, 'public function getTest(') !== false);
@ -104,3 +103,6 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
unlink(__DIR__ . '/EntityGeneratorBook.php'); unlink(__DIR__ . '/EntityGeneratorBook.php');
} }
} }
class EntityGeneratorAuthor {}
class EntityGeneratorComment {}