Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #317 from FabioBatSilva/DDC-1694

Fix DDC-1694
  • Loading branch information...
commit 4ef552e07a98f277c459c6afbf41a7b0958752da 2 parents a038f5e + e997491
@beberlei beberlei authored
View
485 lib/Doctrine/ORM/Tools/EntityGenerator.php
@@ -21,7 +21,8 @@
use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\AssociationMapping,
- Doctrine\Common\Util\Inflector;
+ Doctrine\Common\Util\Inflector,
+ Doctrine\DBAL\Types\Type;
/**
* Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances
@@ -39,7 +40,6 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
- * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
@@ -51,6 +51,7 @@ class EntityGenerator
* Specifies class fields should be protected
*/
const FIELD_VISIBLE_PROTECTED = 'protected';
+
/**
* Specifies class fields should be private
*/
@@ -59,45 +60,106 @@ class EntityGenerator
/**
* @var bool
*/
- private $_backupExisting = true;
+ private $backupExisting = true;
- /** The extension to use for written php files */
- private $_extension = '.php';
+ /**
+ * The extension to use for written php files
+ *
+ * @var string
+ */
+ private $extension = '.php';
- /** Whether or not the current ClassMetadataInfo instance is new or old */
- private $_isNew = true;
+ /**
+ * Whether or not the current ClassMetadataInfo instance is new or old
+ *
+ * @var boolean
+ */
+ private $isNew = true;
- private $_staticReflection = array();
+ /**
+ * @var array
+ */
+ private $staticReflection = array();
- /** Number of spaces to use for indention in generated code */
- private $_numSpaces = 4;
+ /**
+ * Number of spaces to use for indention in generated code
+ */
+ private $numSpaces = 4;
- /** The actual spaces to use for indention */
- private $_spaces = ' ';
+ /**
+ * The actual spaces to use for indention
+ *
+ * @var string
+ */
+ private $spaces = ' ';
- /** The class all generated entities should extend */
- private $_classToExtend;
+ /**
+ * The class all generated entities should extend
+ *
+ * @var string
+ */
+ private $classToExtend;
- /** Whether or not to generation annotations */
- private $_generateAnnotations = false;
+ /**
+ * Whether or not to generation annotations
+ *
+ * @var boolean
+ */
+ private $generateAnnotations = false;
/**
* @var string
*/
- private $_annotationsPrefix = '';
+ private $annotationsPrefix = '';
- /** Whether or not to generated sub methods */
- private $_generateEntityStubMethods = false;
+ /**
+ * Whether or not to generated sub methods
+ *
+ * @var boolean
+ */
+ private $generateEntityStubMethods = false;
- /** Whether or not to update the entity class if it exists already */
- private $_updateEntityIfExists = false;
+ /**
+ * Whether or not to update the entity class if it exists already
+ *
+ * @var boolean
+ */
+ private $updateEntityIfExists = false;
- /** Whether or not to re-generate entity class if it exists already */
- private $_regenerateEntityIfExists = false;
+ /**
+ * Whether or not to re-generate entity class if it exists already
+ *
+ * @var boolean
+ */
+ private $regenerateEntityIfExists = false;
- private $_fieldVisibility = 'private';
+ /**
+ * @var boolean
+ */
+ private $fieldVisibility = 'private';
+
+ /**
+ * Hash-map for handle types
+ *
+ * @var array
+ */
+ private $typeAlias = array(
+ Type::DATETIMETZ => '\DateTime',
+ Type::DATETIME => '\DateTime',
+ Type::DATE => '\DateTime',
+ Type::TIME => '\DateTime',
+ Type::OBJECT => '\stdClass',
+ Type::BIGINT => 'integer',
+ Type::SMALLINT => 'integer',
+ Type::TEXT => 'string',
+ Type::BLOB => 'string',
+ Type::DECIMAL => 'float',
+ );
- private static $_classTemplate =
+ /**
+ * @var string
+ */
+ private static $classTemplate =
'<?php
<namespace>
@@ -111,7 +173,10 @@ class EntityGenerator
}
';
- private static $_getMethodTemplate =
+ /**
+ * @var string
+ */
+ private static $getMethodTemplate =
'/**
* <description>
*
@@ -122,7 +187,10 @@ public function <methodName>()
<spaces>return $this-><fieldName>;
}';
- private static $_setMethodTemplate =
+ /**
+ * @var string
+ */
+ private static $setMethodTemplate =
'/**
* <description>
*
@@ -135,7 +203,10 @@ public function <methodName>(<methodTypeHint>$<variableName><variableDefault>)
<spaces>return $this;
}';
- private static $_addMethodTemplate =
+ /**
+ * @var string
+ */
+ private static $addMethodTemplate =
'/**
* <description>
*
@@ -148,7 +219,10 @@ public function <methodName>(<methodTypeHint>$<variableName>)
<spaces>return $this;
}';
- private static $_lifecycleCallbackMethodTemplate =
+ /**
+ * @var string
+ */
+ private static $lifecycleCallbackMethodTemplate =
'/**
* @<name>
*/
@@ -157,7 +231,10 @@ public function <methodName>()
<spaces>// Add your code here
}';
- private static $_constructorMethodTemplate =
+ /**
+ * @var string
+ */
+ private static $constructorMethodTemplate =
'public function __construct()
{
<spaces><collections>
@@ -167,7 +244,7 @@ public function <methodName>()
public function __construct()
{
if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) {
- $this->_annotationsPrefix = 'ORM\\';
+ $this->annotationsPrefix = 'ORM\\';
}
}
@@ -194,22 +271,22 @@ public function generate(array $metadatas, $outputDirectory)
*/
public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
{
- $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->_extension;
+ $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->extension;
$dir = dirname($path);
if ( ! is_dir($dir)) {
mkdir($dir, 0777, true);
}
- $this->_isNew = !file_exists($path) || (file_exists($path) && $this->_regenerateEntityIfExists);
+ $this->isNew = !file_exists($path) || (file_exists($path) && $this->regenerateEntityIfExists);
- if ( ! $this->_isNew) {
- $this->_parseTokensInEntityFile(file_get_contents($path));
+ if ( ! $this->isNew) {
+ $this->parseTokensInEntityFile(file_get_contents($path));
} else {
- $this->_staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array());
+ $this->staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array());
}
- if ($this->_backupExisting && file_exists($path)) {
+ if ($this->backupExisting && file_exists($path)) {
$backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~";
if (!copy($path, $backupPath)) {
throw new \RuntimeException("Attempt to backup overwritten entity file but copy operation failed.");
@@ -217,10 +294,10 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
}
// If entity doesn't exist or we're re-generating the entities entirely
- if ($this->_isNew) {
+ if ($this->isNew) {
file_put_contents($path, $this->generateEntityClass($metadata));
// If entity exists and we're allowed to update the entity class
- } else if ( ! $this->_isNew && $this->_updateEntityIfExists) {
+ } else if ( ! $this->isNew && $this->updateEntityIfExists) {
file_put_contents($path, $this->generateUpdatedEntityClass($metadata, $path));
}
}
@@ -241,14 +318,14 @@ public function generateEntityClass(ClassMetadataInfo $metadata)
);
$replacements = array(
- $this->_generateEntityNamespace($metadata),
- $this->_generateEntityDocBlock($metadata),
- $this->_generateEntityClassName($metadata),
- $this->_generateEntityBody($metadata)
+ $this->generateEntityNamespace($metadata),
+ $this->generateEntityDocBlock($metadata),
+ $this->generateEntityClassName($metadata),
+ $this->generateEntityBody($metadata)
);
- $code = str_replace($placeHolders, $replacements, self::$_classTemplate);
- return str_replace('<spaces>', $this->_spaces, $code);
+ $code = str_replace($placeHolders, $replacements, self::$classTemplate);
+ return str_replace('<spaces>', $this->spaces, $code);
}
/**
@@ -262,8 +339,8 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
{
$currentCode = file_get_contents($path);
- $body = $this->_generateEntityBody($metadata);
- $body = str_replace('<spaces>', $this->_spaces, $body);
+ $body = $this->generateEntityBody($metadata);
+ $body = str_replace('<spaces>', $this->spaces, $body);
$last = strrpos($currentCode, '}');
return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : ''). "}";
@@ -277,8 +354,8 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
*/
public function setNumSpaces($numSpaces)
{
- $this->_spaces = str_repeat(' ', $numSpaces);
- $this->_numSpaces = $numSpaces;
+ $this->spaces = str_repeat(' ', $numSpaces);
+ $this->numSpaces = $numSpaces;
}
/**
@@ -289,7 +366,7 @@ public function setNumSpaces($numSpaces)
*/
public function setExtension($extension)
{
- $this->_extension = $extension;
+ $this->extension = $extension;
}
/**
@@ -299,7 +376,7 @@ public function setExtension($extension)
*/
public function setClassToExtend($classToExtend)
{
- $this->_classToExtend = $classToExtend;
+ $this->classToExtend = $classToExtend;
}
/**
@@ -310,7 +387,7 @@ public function setClassToExtend($classToExtend)
*/
public function setGenerateAnnotations($bool)
{
- $this->_generateAnnotations = $bool;
+ $this->generateAnnotations = $bool;
}
/**
@@ -325,7 +402,7 @@ public function setFieldVisibility($visibility)
throw new \InvalidArgumentException('Invalid provided visibilty (only private and protected are allowed): ' . $visibility);
}
- $this->_fieldVisibility = $visibility;
+ $this->fieldVisibility = $visibility;
}
/**
@@ -335,7 +412,7 @@ public function setFieldVisibility($visibility)
*/
public function setAnnotationPrefix($prefix)
{
- $this->_annotationsPrefix = $prefix;
+ $this->annotationsPrefix = $prefix;
}
/**
@@ -346,7 +423,7 @@ public function setAnnotationPrefix($prefix)
*/
public function setUpdateEntityIfExists($bool)
{
- $this->_updateEntityIfExists = $bool;
+ $this->updateEntityIfExists = $bool;
}
/**
@@ -357,7 +434,7 @@ public function setUpdateEntityIfExists($bool)
*/
public function setRegenerateEntityIfExists($bool)
{
- $this->_regenerateEntityIfExists = $bool;
+ $this->regenerateEntityIfExists = $bool;
}
/**
@@ -368,7 +445,7 @@ public function setRegenerateEntityIfExists($bool)
*/
public function setGenerateStubMethods($bool)
{
- $this->_generateEntityStubMethods = $bool;
+ $this->generateEntityStubMethods = $bool;
}
/**
@@ -376,28 +453,41 @@ public function setGenerateStubMethods($bool)
*/
public function setBackupExisting($bool)
{
- $this->_backupExisting = $bool;
+ $this->backupExisting = $bool;
}
- private function _generateEntityNamespace(ClassMetadataInfo $metadata)
+ /**
+ * @param string $type
+ * @return string
+ */
+ private function getType($type)
{
- if ($this->_hasNamespace($metadata)) {
- return 'namespace ' . $this->_getNamespace($metadata) .';';
+ if (isset($this->typeAlias[$type])) {
+ return $this->typeAlias[$type];
}
+
+ return $type;
}
- private function _generateEntityClassName(ClassMetadataInfo $metadata)
+ private function generateEntityNamespace(ClassMetadataInfo $metadata)
{
- return 'class ' . $this->_getClassName($metadata) .
- ($this->_extendsClass() ? ' extends ' . $this->_getClassToExtendName() : null);
+ if ($this->hasNamespace($metadata)) {
+ return 'namespace ' . $this->getNamespace($metadata) .';';
+ }
}
- private function _generateEntityBody(ClassMetadataInfo $metadata)
+ private function generateEntityClassName(ClassMetadataInfo $metadata)
{
- $fieldMappingProperties = $this->_generateEntityFieldMappingProperties($metadata);
- $associationMappingProperties = $this->_generateEntityAssociationMappingProperties($metadata);
- $stubMethods = $this->_generateEntityStubMethods ? $this->_generateEntityStubMethods($metadata) : null;
- $lifecycleCallbackMethods = $this->_generateEntityLifecycleCallbackMethods($metadata);
+ return 'class ' . $this->getClassName($metadata) .
+ ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null);
+ }
+
+ private function generateEntityBody(ClassMetadataInfo $metadata)
+ {
+ $fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata);
+ $associationMappingProperties = $this->generateEntityAssociationMappingProperties($metadata);
+ $stubMethods = $this->generateEntityStubMethods ? $this->generateEntityStubMethods($metadata) : null;
+ $lifecycleCallbackMethods = $this->generateEntityLifecycleCallbackMethods($metadata);
$code = array();
@@ -409,7 +499,7 @@ private function _generateEntityBody(ClassMetadataInfo $metadata)
$code[] = $associationMappingProperties;
}
- $code[] = $this->_generateEntityConstructor($metadata);
+ $code[] = $this->generateEntityConstructor($metadata);
if ($stubMethods) {
$code[] = $stubMethods;
@@ -422,9 +512,9 @@ private function _generateEntityBody(ClassMetadataInfo $metadata)
return implode("\n", $code);
}
- private function _generateEntityConstructor(ClassMetadataInfo $metadata)
+ private function generateEntityConstructor(ClassMetadataInfo $metadata)
{
- if ($this->_hasMethod('__construct', $metadata)) {
+ if ($this->hasMethod('__construct', $metadata)) {
return '';
}
@@ -437,7 +527,7 @@ private function _generateEntityConstructor(ClassMetadataInfo $metadata)
}
if ($collections) {
- return $this->_prefixCodeWithSpaces(str_replace("<collections>", implode("\n".$this->_spaces, $collections), self::$_constructorMethodTemplate));
+ return $this->prefixCodeWithSpaces(str_replace("<collections>", implode("\n".$this->spaces, $collections), self::$constructorMethodTemplate));
}
return '';
@@ -447,7 +537,7 @@ private function _generateEntityConstructor(ClassMetadataInfo $metadata)
* @todo this won't work if there is a namespace in brackets and a class outside of it.
* @param string $src
*/
- private function _parseTokensInEntityFile($src)
+ private function parseTokensInEntityFile($src)
{
$tokens = token_get_all($src);
$lastSeenNamespace = "";
@@ -472,8 +562,8 @@ private function _parseTokensInEntityFile($src)
if ($inClass) {
$inClass = false;
$lastSeenClass = $lastSeenNamespace . ($lastSeenNamespace ? '\\' : '') . $token[1];
- $this->_staticReflection[$lastSeenClass]['properties'] = array();
- $this->_staticReflection[$lastSeenClass]['methods'] = array();
+ $this->staticReflection[$lastSeenClass]['properties'] = array();
+ $this->staticReflection[$lastSeenClass]['methods'] = array();
}
if ($token[0] == T_NAMESPACE) {
@@ -483,95 +573,95 @@ private function _parseTokensInEntityFile($src)
$inClass = true;
} else if ($token[0] == T_FUNCTION) {
if ($tokens[$i+2][0] == T_STRING) {
- $this->_staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+2][1];
+ $this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+2][1];
} else if ($tokens[$i+2] == "&" && $tokens[$i+3][0] == T_STRING) {
- $this->_staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+3][1];
+ $this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+3][1];
}
} else if (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED)) && $tokens[$i+2][0] != T_FUNCTION) {
- $this->_staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1);
+ $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1);
}
}
}
- private function _hasProperty($property, ClassMetadataInfo $metadata)
+ private function hasProperty($property, ClassMetadataInfo $metadata)
{
- if ($this->_extendsClass()) {
+ if ($this->extendsClass()) {
// don't generate property if its already on the base class.
- $reflClass = new \ReflectionClass($this->_getClassToExtend());
+ $reflClass = new \ReflectionClass($this->getClassToExtend());
if ($reflClass->hasProperty($property)) {
return true;
}
}
return (
- isset($this->_staticReflection[$metadata->name]) &&
- in_array($property, $this->_staticReflection[$metadata->name]['properties'])
+ isset($this->staticReflection[$metadata->name]) &&
+ in_array($property, $this->staticReflection[$metadata->name]['properties'])
);
}
- private function _hasMethod($method, ClassMetadataInfo $metadata)
+ private function hasMethod($method, ClassMetadataInfo $metadata)
{
- if ($this->_extendsClass()) {
+ if ($this->extendsClass()) {
// don't generate method if its already on the base class.
- $reflClass = new \ReflectionClass($this->_getClassToExtend());
+ $reflClass = new \ReflectionClass($this->getClassToExtend());
if ($reflClass->hasMethod($method)) {
return true;
}
}
return (
- isset($this->_staticReflection[$metadata->name]) &&
- in_array($method, $this->_staticReflection[$metadata->name]['methods'])
+ isset($this->staticReflection[$metadata->name]) &&
+ in_array($method, $this->staticReflection[$metadata->name]['methods'])
);
}
- private function _hasNamespace(ClassMetadataInfo $metadata)
+ private function hasNamespace(ClassMetadataInfo $metadata)
{
return strpos($metadata->name, '\\') ? true : false;
}
- private function _extendsClass()
+ private function extendsClass()
{
- return $this->_classToExtend ? true : false;
+ return $this->classToExtend ? true : false;
}
- private function _getClassToExtend()
+ private function getClassToExtend()
{
- return $this->_classToExtend;
+ return $this->classToExtend;
}
- private function _getClassToExtendName()
+ private function getClassToExtendName()
{
- $refl = new \ReflectionClass($this->_getClassToExtend());
+ $refl = new \ReflectionClass($this->getClassToExtend());
return '\\' . $refl->getName();
}
- private function _getClassName(ClassMetadataInfo $metadata)
+ private function getClassName(ClassMetadataInfo $metadata)
{
return ($pos = strrpos($metadata->name, '\\'))
? substr($metadata->name, $pos + 1, strlen($metadata->name)) : $metadata->name;
}
- private function _getNamespace(ClassMetadataInfo $metadata)
+ private function getNamespace(ClassMetadataInfo $metadata)
{
return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
}
- private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
+ private function generateEntityDocBlock(ClassMetadataInfo $metadata)
{
$lines = array();
$lines[] = '/**';
$lines[] = ' * '.$metadata->name;
- if ($this->_generateAnnotations) {
+ if ($this->generateAnnotations) {
$lines[] = ' *';
$methods = array(
- '_generateTableAnnotation',
- '_generateInheritanceAnnotation',
- '_generateDiscriminatorColumnAnnotation',
- '_generateDiscriminatorMapAnnotation'
+ 'generateTableAnnotation',
+ 'generateInheritanceAnnotation',
+ 'generateDiscriminatorColumnAnnotation',
+ 'generateDiscriminatorMapAnnotation'
);
foreach ($methods as $method) {
@@ -581,9 +671,9 @@ private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
}
if ($metadata->isMappedSuperclass) {
- $lines[] = ' * @' . $this->_annotationsPrefix . 'MappedSuperClass';
+ $lines[] = ' * @' . $this->annotationsPrefix . 'MappedSuperClass';
} else {
- $lines[] = ' * @' . $this->_annotationsPrefix . 'Entity';
+ $lines[] = ' * @' . $this->annotationsPrefix . 'Entity';
}
if ($metadata->customRepositoryClassName) {
@@ -591,7 +681,7 @@ private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
}
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
- $lines[] = ' * @' . $this->_annotationsPrefix . 'HasLifecycleCallbacks';
+ $lines[] = ' * @' . $this->annotationsPrefix . 'HasLifecycleCallbacks';
}
}
@@ -600,7 +690,7 @@ private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
return implode("\n", $lines);
}
- private function _generateTableAnnotation($metadata)
+ private function generateTableAnnotation($metadata)
{
$table = array();
@@ -613,19 +703,19 @@ private function _generateTableAnnotation($metadata)
}
if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) {
- $constraints = $this->_generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
+ $constraints = $this->generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
$table[] = 'uniqueConstraints={' . $constraints . '}';
}
if (isset($metadata->table['indexes']) && $metadata->table['indexes']) {
- $constraints = $this->_generateTableConstraints('Index', $metadata->table['indexes']);
+ $constraints = $this->generateTableConstraints('Index', $metadata->table['indexes']);
$table[] = 'indexes={' . $constraints . '}';
}
- return '@' . $this->_annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
+ return '@' . $this->annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
}
- private function _generateTableConstraints($constraintName, $constraints)
+ private function generateTableConstraints($constraintName, $constraints)
{
$annotations = array();
foreach ($constraints as $name => $constraint) {
@@ -633,19 +723,19 @@ private function _generateTableConstraints($constraintName, $constraints)
foreach ($constraint['columns'] as $column) {
$columns[] = '"' . $column . '"';
}
- $annotations[] = '@' . $this->_annotationsPrefix . $constraintName . '(name="' . $name . '", columns={' . implode(', ', $columns) . '})';
+ $annotations[] = '@' . $this->annotationsPrefix . $constraintName . '(name="' . $name . '", columns={' . implode(', ', $columns) . '})';
}
return implode(', ', $annotations);
}
- private function _generateInheritanceAnnotation($metadata)
+ private function generateInheritanceAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
- return '@' . $this->_annotationsPrefix . 'InheritanceType("'.$this->_getInheritanceTypeString($metadata->inheritanceType).'")';
+ return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")';
}
}
- private function _generateDiscriminatorColumnAnnotation($metadata)
+ private function generateDiscriminatorColumnAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
$discrColumn = $metadata->discriminatorValue;
@@ -653,11 +743,11 @@ private function _generateDiscriminatorColumnAnnotation($metadata)
. '", type="' . $discrColumn['type']
. '", length=' . $discrColumn['length'];
- return '@' . $this->_annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')';
+ return '@' . $this->annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')';
}
}
- private function _generateDiscriminatorMapAnnotation($metadata)
+ private function generateDiscriminatorMapAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
$inheritanceClassMap = array();
@@ -666,40 +756,40 @@ private function _generateDiscriminatorMapAnnotation($metadata)
$inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"';
}
- return '@' . $this->_annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
+ return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
}
}
- private function _generateEntityStubMethods(ClassMetadataInfo $metadata)
+ private function generateEntityStubMethods(ClassMetadataInfo $metadata)
{
$methods = array();
foreach ($metadata->fieldMappings as $fieldMapping) {
if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id'] || $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE) {
- if ($code = $this->_generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) {
+ if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) {
$methods[] = $code;
}
}
- if ($code = $this->_generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) {
+ if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) {
$methods[] = $code;
}
}
foreach ($metadata->associationMappings as $associationMapping) {
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) {
- $nullable = $this->_isAssociationIsNullable($associationMapping) ? 'null' : null;
- if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) {
+ $nullable = $this->isAssociationIsNullable($associationMapping) ? 'null' : null;
+ if ($code = $this->generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) {
$methods[] = $code;
}
- if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
+ if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
$methods[] = $code;
}
} else if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) {
- if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
+ if ($code = $this->generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
$methods[] = $code;
}
- if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) {
+ if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) {
$methods[] = $code;
}
}
@@ -708,7 +798,7 @@ private function _generateEntityStubMethods(ClassMetadataInfo $metadata)
return implode("\n\n", $methods);
}
- private function _isAssociationIsNullable($associationMapping)
+ private function isAssociationIsNullable($associationMapping)
{
if (isset($associationMapping['id']) && $associationMapping['id']) {
return false;
@@ -727,14 +817,14 @@ private function _isAssociationIsNullable($associationMapping)
return true;
}
- private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
+ private function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
{
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
$methods = array();
foreach ($metadata->lifecycleCallbacks as $name => $callbacks) {
foreach ($callbacks as $callback) {
- if ($code = $this->_generateLifecycleCallbackMethod($name, $callback, $metadata)) {
+ if ($code = $this->generateLifecycleCallbackMethod($name, $callback, $metadata)) {
$methods[] = $code;
}
}
@@ -746,42 +836,42 @@ private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $meta
return "";
}
- private function _generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
+ private function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
{
$lines = array();
foreach ($metadata->associationMappings as $associationMapping) {
- if ($this->_hasProperty($associationMapping['fieldName'], $metadata)) {
+ if ($this->hasProperty($associationMapping['fieldName'], $metadata)) {
continue;
}
- $lines[] = $this->_generateAssociationMappingPropertyDocBlock($associationMapping, $metadata);
- $lines[] = $this->_spaces . $this->_fieldVisibility . ' $' . $associationMapping['fieldName']
+ $lines[] = $this->generateAssociationMappingPropertyDocBlock($associationMapping, $metadata);
+ $lines[] = $this->spaces . $this->fieldVisibility . ' $' . $associationMapping['fieldName']
. ($associationMapping['type'] == 'manyToMany' ? ' = array()' : null) . ";\n";
}
return implode("\n", $lines);
}
- private function _generateEntityFieldMappingProperties(ClassMetadataInfo $metadata)
+ private function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata)
{
$lines = array();
foreach ($metadata->fieldMappings as $fieldMapping) {
- if ($this->_hasProperty($fieldMapping['fieldName'], $metadata) ||
+ if ($this->hasProperty($fieldMapping['fieldName'], $metadata) ||
$metadata->isInheritedField($fieldMapping['fieldName'])) {
continue;
}
- $lines[] = $this->_generateFieldMappingPropertyDocBlock($fieldMapping, $metadata);
- $lines[] = $this->_spaces . $this->_fieldVisibility . ' $' . $fieldMapping['fieldName']
+ $lines[] = $this->generateFieldMappingPropertyDocBlock($fieldMapping, $metadata);
+ $lines[] = $this->spaces . $this->fieldVisibility . ' $' . $fieldMapping['fieldName']
. (isset($fieldMapping['default']) ? ' = ' . var_export($fieldMapping['default'], true) : null) . ";\n";
}
return implode("\n", $lines);
}
- private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
+ private function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
if ($type == "add") {
$addMethod = explode("\\", $typeHint);
@@ -791,17 +881,16 @@ private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $
$methodName = $type . Inflector::classify($fieldName);
}
- if ($this->_hasMethod($methodName, $metadata)) {
+ if ($this->hasMethod($methodName, $metadata)) {
return;
}
- $this->_staticReflection[$metadata->name]['methods'][] = $methodName;
+ $this->staticReflection[$metadata->name]['methods'][] = $methodName;
- $var = sprintf('_%sMethodTemplate', $type);
+ $var = sprintf('%sMethodTemplate', $type);
$template = self::$$var;
- $variableType = $typeHint ? $typeHint . ' ' : null;
-
- $types = \Doctrine\DBAL\Types\Type::getTypesMap();
+ $types = Type::getTypesMap();
+ $variableType = $typeHint ? $this->getType($typeHint) . ' ' : null;
$methodTypeHint = $typeHint && ! isset($types[$typeHint]) ? '\\' . $typeHint . ' ' : null;
$replacements = array(
@@ -812,7 +901,7 @@ private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $
'<methodName>' => $methodName,
'<fieldName>' => $fieldName,
'<variableDefault>' => ($defaultValue !== null ) ? (' = '.$defaultValue) : '',
- '<entity>' => $this->_getClassName($metadata)
+ '<entity>' => $this->getClassName($metadata)
);
$method = str_replace(
@@ -821,31 +910,31 @@ private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $
$template
);
- return $this->_prefixCodeWithSpaces($method);
+ return $this->prefixCodeWithSpaces($method);
}
- private function _generateLifecycleCallbackMethod($name, $methodName, $metadata)
+ private function generateLifecycleCallbackMethod($name, $methodName, $metadata)
{
- if ($this->_hasMethod($methodName, $metadata)) {
+ if ($this->hasMethod($methodName, $metadata)) {
return;
}
- $this->_staticReflection[$metadata->name]['methods'][] = $methodName;
+ $this->staticReflection[$metadata->name]['methods'][] = $methodName;
$replacements = array(
- '<name>' => $this->_annotationsPrefix . ucfirst($name),
+ '<name>' => $this->annotationsPrefix . ucfirst($name),
'<methodName>' => $methodName,
);
$method = str_replace(
array_keys($replacements),
array_values($replacements),
- self::$_lifecycleCallbackMethodTemplate
+ self::$lifecycleCallbackMethodTemplate
);
- return $this->_prefixCodeWithSpaces($method);
+ return $this->prefixCodeWithSpaces($method);
}
- private function _generateJoinColumnAnnotation(array $joinColumn)
+ private function generateJoinColumnAnnotation(array $joinColumn)
{
$joinColumnAnnot = array();
@@ -873,28 +962,28 @@ private function _generateJoinColumnAnnotation(array $joinColumn)
$joinColumnAnnot[] = 'columnDefinition="' . $joinColumn['columnDefinition'] . '"';
}
- return '@' . $this->_annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
+ return '@' . $this->annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
}
- private function _generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata)
+ private function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata)
{
$lines = array();
- $lines[] = $this->_spaces . '/**';
+ $lines[] = $this->spaces . '/**';
if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) {
- $lines[] = $this->_spaces . ' * @var \Doctrine\Common\Collections\ArrayCollection';
+ $lines[] = $this->spaces . ' * @var \Doctrine\Common\Collections\ArrayCollection';
} else {
- $lines[] = $this->_spaces . ' * @var ' . $associationMapping['targetEntity'];
+ $lines[] = $this->spaces . ' * @var ' . $associationMapping['targetEntity'];
}
- if ($this->_generateAnnotations) {
- $lines[] = $this->_spaces . ' *';
+ if ($this->generateAnnotations) {
+ $lines[] = $this->spaces . ' *';
if (isset($associationMapping['id']) && $associationMapping['id']) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Id';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Id';
- if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
+ if ($generatorType = $this->getIdGeneratorTypeString($metadata->generatorType)) {
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
}
}
@@ -943,21 +1032,21 @@ private function _generateAssociationMappingPropertyDocBlock(array $associationM
$typeOptions[] = 'orphanRemoval=' . ($associationMapping['orphanRemoval'] ? 'true' : 'false');
}
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . '' . $type . '(' . implode(', ', $typeOptions) . ')';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . '' . $type . '(' . implode(', ', $typeOptions) . ')';
if (isset($associationMapping['joinColumns']) && $associationMapping['joinColumns']) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'JoinColumns({';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'JoinColumns({';
$joinColumnsLines = array();
foreach ($associationMapping['joinColumns'] as $joinColumn) {
- if ($joinColumnAnnot = $this->_generateJoinColumnAnnotation($joinColumn)) {
- $joinColumnsLines[] = $this->_spaces . ' * ' . $joinColumnAnnot;
+ if ($joinColumnAnnot = $this->generateJoinColumnAnnotation($joinColumn)) {
+ $joinColumnsLines[] = $this->spaces . ' * ' . $joinColumnAnnot;
}
}
$lines[] = implode(",\n", $joinColumnsLines);
- $lines[] = $this->_spaces . ' * })';
+ $lines[] = $this->spaces . ' * })';
}
if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) {
@@ -968,49 +1057,49 @@ private function _generateAssociationMappingPropertyDocBlock(array $associationM
$joinTable[] = 'schema="' . $associationMapping['joinTable']['schema'] . '"';
}
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'JoinTable(' . implode(', ', $joinTable) . ',';
- $lines[] = $this->_spaces . ' * joinColumns={';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'JoinTable(' . implode(', ', $joinTable) . ',';
+ $lines[] = $this->spaces . ' * joinColumns={';
foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) {
- $lines[] = $this->_spaces . ' * ' . $this->_generateJoinColumnAnnotation($joinColumn);
+ $lines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
}
- $lines[] = $this->_spaces . ' * },';
- $lines[] = $this->_spaces . ' * inverseJoinColumns={';
+ $lines[] = $this->spaces . ' * },';
+ $lines[] = $this->spaces . ' * inverseJoinColumns={';
foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
- $lines[] = $this->_spaces . ' * ' . $this->_generateJoinColumnAnnotation($joinColumn);
+ $lines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn);
}
- $lines[] = $this->_spaces . ' * }';
- $lines[] = $this->_spaces . ' * )';
+ $lines[] = $this->spaces . ' * }';
+ $lines[] = $this->spaces . ' * )';
}
if (isset($associationMapping['orderBy'])) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'OrderBy({';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'OrderBy({';
foreach ($associationMapping['orderBy'] as $name => $direction) {
- $lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",';
+ $lines[] = $this->spaces . ' * "' . $name . '"="' . $direction . '",';
}
$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);
}
- private function _generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
+ private function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
{
$lines = array();
- $lines[] = $this->_spaces . '/**';
- $lines[] = $this->_spaces . ' * @var ' . $fieldMapping['type'] . ' $' . $fieldMapping['fieldName'];
+ $lines[] = $this->spaces . '/**';
+ $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ' $' . $fieldMapping['fieldName'];
- if ($this->_generateAnnotations) {
- $lines[] = $this->_spaces . ' *';
+ if ($this->generateAnnotations) {
+ $lines[] = $this->spaces . ' *';
$column = array();
if (isset($fieldMapping['columnName'])) {
@@ -1045,13 +1134,13 @@ private function _generateFieldMappingPropertyDocBlock(array $fieldMapping, Clas
$column[] = 'unique=' . var_export($fieldMapping['unique'], true);
}
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Column(' . implode(', ', $column) . ')';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Column(' . implode(', ', $column) . ')';
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Id';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Id';
- if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
- $lines[] = $this->_spaces.' * @' . $this->_annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
+ if ($generatorType = $this->getIdGeneratorTypeString($metadata->generatorType)) {
+ $lines[] = $this->spaces.' * @' . $this->annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
}
if ($metadata->sequenceGeneratorDefinition) {
@@ -1069,32 +1158,32 @@ private function _generateFieldMappingPropertyDocBlock(array $fieldMapping, Clas
$sequenceGenerator[] = 'initialValue=' . $metadata->sequenceGeneratorDefinition['initialValue'];
}
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
}
}
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
- $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Version';
+ $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'Version';
}
}
- $lines[] = $this->_spaces . ' */';
+ $lines[] = $this->spaces . ' */';
return implode("\n", $lines);
}
- private function _prefixCodeWithSpaces($code, $num = 1)
+ private function prefixCodeWithSpaces($code, $num = 1)
{
$lines = explode("\n", $code);
foreach ($lines as $key => $value) {
- $lines[$key] = str_repeat($this->_spaces, $num) . $lines[$key];
+ $lines[$key] = str_repeat($this->spaces, $num) . $lines[$key];
}
return implode("\n", $lines);
}
- private function _getInheritanceTypeString($type)
+ private function getInheritanceTypeString($type)
{
switch ($type) {
case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
@@ -1114,7 +1203,7 @@ private function _getInheritanceTypeString($type)
}
}
- private function _getChangeTrackingPolicyString($policy)
+ private function getChangeTrackingPolicyString($policy)
{
switch ($policy) {
case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
@@ -1131,7 +1220,7 @@ private function _getChangeTrackingPolicyString($policy)
}
}
- private function _getIdGeneratorTypeString($type)
+ private function getIdGeneratorTypeString($type)
{
switch ($type) {
case ClassMetadataInfo::GENERATOR_TYPE_AUTO:
View
154 tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
@@ -11,6 +11,10 @@
class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
{
+
+ /**
+ * @var EntityGenerator
+ */
private $_generator;
private $_tmpDir;
private $_namespace;
@@ -75,6 +79,24 @@ public function generateBookEntityFixture()
return $metadata;
}
+ private function generateEntityTypeFixture(array $field)
+ {
+ $metadata = new ClassMetadataInfo($this->_namespace . '\EntityType');
+ $metadata->namespace = $this->_namespace;
+
+ $metadata->table['name'] = 'entity_type';
+ $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
+ $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
+
+ $name = $field['fieldName'];
+ $type = $field['dbType'];
+ $metadata->mapField(array('fieldName' => $name, 'type' => $type));
+
+ $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
+
+ return $metadata;
+ }
+
/**
* @param ClassMetadataInfo $metadata
* @return EntityGeneratorBook
@@ -212,10 +234,10 @@ public function testLoadPrefixedMetadata()
public function testParseTokensInEntityFile($php, $classes)
{
$r = new \ReflectionObject($this->_generator);
- $m = $r->getMethod('_parseTokensInEntityFile');
+ $m = $r->getMethod('parseTokensInEntityFile');
$m->setAccessible(true);
- $p = $r->getProperty('_staticReflection');
+ $p = $r->getProperty('staticReflection');
$p->setAccessible(true);
$ret = $m->invoke($this->_generator, $php);
@@ -254,6 +276,104 @@ public function testGenerateEntityWithSequenceGenerator()
$this->assertContains('@SequenceGenerator(sequenceName="DDC1784_ID_SEQ", allocationSize=1, initialValue=2)', $docComment);
}
+ /**
+ * @dataProvider getEntityTypeAliasDataProvider
+ *
+ * @group DDC-1694
+ */
+ public function testEntityTypeAlias(array $field)
+ {
+ $metadata = $this->generateEntityTypeFixture($field);
+ $path = $this->_tmpDir . '/'. $this->_namespace . '/EntityType.php';
+
+ $this->assertFileExists($path);
+ require_once $path;
+
+ $entity = new $metadata->name;
+ $reflClass = new \ReflectionClass($metadata->name);
+
+ $type = $field['phpType'];
+ $name = $field['fieldName'];
+ $value = $field['value'];
+ $getter = "get" . ucfirst($name);
+ $setter = "set" . ucfirst($name);
+
+ $this->assertPhpDocVarType($type, $reflClass->getProperty($name));
+ $this->assertPhpDocParamType($type, $reflClass->getMethod($setter));
+ $this->assertPhpDocReturnType($type, $reflClass->getMethod($getter));
+
+ $this->assertSame($entity, $entity->{$setter}($value));
+ $this->assertEquals($value, $entity->{$getter}());
+ }
+
+ /**
+ * @return array
+ */
+ public function getEntityTypeAliasDataProvider()
+ {
+ return array(
+ array(array(
+ 'fieldName' => 'datetimetz',
+ 'phpType' => '\\DateTime',
+ 'dbType' => 'datetimetz',
+ 'value' => new \DateTime
+ )),
+ array(array(
+ 'fieldName' => 'datetime',
+ 'phpType' => '\\DateTime',
+ 'dbType' => 'datetime',
+ 'value' => new \DateTime
+ )),
+ array(array(
+ 'fieldName' => 'date',
+ 'phpType' => '\\DateTime',
+ 'dbType' => 'date',
+ 'value' => new \DateTime
+ )),
+ array(array(
+ 'fieldName' => 'time',
+ 'phpType' => '\DateTime',
+ 'dbType' => 'time',
+ 'value' => new \DateTime
+ )),
+ array(array(
+ 'fieldName' => 'object',
+ 'phpType' => '\stdClass',
+ 'dbType' => 'object',
+ 'value' => new \stdClass()
+ )),
+ array(array(
+ 'fieldName' => 'bigint',
+ 'phpType' => 'integer',
+ 'dbType' => 'bigint',
+ 'value' => 11
+ )),
+ array(array(
+ 'fieldName' => 'smallint',
+ 'phpType' => 'integer',
+ 'dbType' => 'smallint',
+ 'value' => 22
+ )),
+ array(array(
+ 'fieldName' => 'text',
+ 'phpType' => 'string',
+ 'dbType' => 'text',
+ 'value' => 'text'
+ )),
+ array(array(
+ 'fieldName' => 'blob',
+ 'phpType' => 'string',
+ 'dbType' => 'blob',
+ 'value' => 'blob'
+ )),
+ array(array(
+ 'fieldName' => 'decimal',
+ 'phpType' => 'float',
+ 'dbType' => 'decimal',
+ 'value' => 33.33
+ ),
+ ));
+ }
public function getParseTokensInEntityFileData()
{
@@ -286,6 +406,36 @@ class
),
);
}
+
+ /**
+ * @param string $type
+ * @param \ReflectionProperty $property
+ */
+ private function assertPhpDocVarType($type, \ReflectionProperty $property)
+ {
+ $this->assertEquals(1, preg_match('/@var\s+([^\s]+)/',$property->getDocComment(), $matches));
+ $this->assertEquals($type, $matches[1]);
+ }
+
+ /**
+ * @param string $type
+ * @param \ReflectionProperty $method
+ */
+ private function assertPhpDocReturnType($type, \ReflectionMethod $method)
+ {
+ $this->assertEquals(1, preg_match('/@return\s+([^\s]+)/', $method->getDocComment(), $matches));
+ $this->assertEquals($type, $matches[1]);
+ }
+
+ /**
+ * @param string $type
+ * @param \ReflectionProperty $method
+ */
+ private function assertPhpDocParamType($type, \ReflectionMethod $method)
+ {
+ $this->assertEquals(1, preg_match('/@param\s+([^\s]+)/', $method->getDocComment(), $matches));
+ $this->assertEquals($type, $matches[1]);
+ }
}
class EntityGeneratorAuthor {}
Please sign in to comment.
Something went wrong with that request. Please try again.