Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6] Added ENUM column type and modified ActiveRecord builder to han…

…dle it seamlessly (refs #1177)
  • Loading branch information...
commit 5d24ca62cf40f5fb21d87022401714869d6a1443 1 parent 881178f
@fzaninotto fzaninotto authored
View
2  docs/reference/Schema.txt
@@ -188,7 +188,7 @@ According to the schema, `name` is the only required attribute. Also, the `idMe
* `lazyLoad` A lazy-loaded column is not fetched from the database by model queries. Only the generated getter method for such a column issues a query to the database. Useful for large column types (such as CLOB and BLOB).
* `primaryString` A column defined as primary string serves as default value for a `__toString()` method in the generated Propel object.
- '''Tip''': For performance reasons, it is often a good idea to set BLOB and CLOB columns as lazyLoaded. A resultset containing one of more very large columns takes time to transit between the database and the PHP server, so you want to make sure this only happen when you actually need it.
+'''Tip''': For performance reasons, it is often a good idea to set BLOB and CLOB columns as lazyLoaded. A resultset containing one of more very large columns takes time to transit between the database and the PHP server, so you want to make sure this only happen when you actually need it.
=== <foreign-key> element ===
View
4 generator/lib/builder/om/ObjectBuilder.php
@@ -65,6 +65,8 @@ protected function addColumnAccessorMethods(&$script)
if ($col->isNamePlural()) {
$this->addHasArrayElement($script, $col);
}
+ } else if ($col->isEnumType()) {
+ $this->addEnumAccessor($script, $col);
} else {
$this->addDefaultAccessor($script, $col);
}
@@ -96,6 +98,8 @@ protected function addColumnMutatorMethods(&$script)
$this->addAddArrayElement($script, $col);
$this->addRemoveArrayElement($script, $col);
}
+ } else if ($col->isEnumType()) {
+ $this->addEnumMutator($script, $col);
} else {
$this->addDefaultMutator($script, $col);
}
View
75 generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -967,6 +967,49 @@ protected function addArrayAccessorBody(&$script, Column $col)
}
/**
+ * Adds an enum getter method.
+ * @param string &$script The script will be modified in this method.
+ * @param Column $col The current column.
+ * @see parent::addColumnAccessors()
+ */
+ protected function addEnumAccessor(&$script, Column $col)
+ {
+ $this->addDefaultAccessorComment($script, $col);
+ $this->addDefaultAccessorOpen($script, $col);
+ $this->addEnumAccessorBody($script, $col);
+ $this->addDefaultAccessorClose($script, $col);
+ }
+
+ /**
+ * Adds the function body for an enum accessor method
+ * @param string &$script The script will be modified in this method.
+ * @param Column $col The current column.
+ * @see addDefaultAccessor()
+ **/
+ protected function addEnumAccessorBody(&$script, Column $col)
+ {
+ $cfc = $col->getPhpName();
+ $clo = strtolower($col->getName());
+ if ($col->isLazyLoad()) {
+ $script .= "
+ if (!\$this->".$clo."_isLoaded && \$this->$clo === null && !\$this->isNew()) {
+ \$this->load$cfc(\$con);
+ }
+";
+ }
+
+ $script .= "
+ if (null === \$this->$clo) {
+ return null;
+ }
+ \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . ");
+ if (!isset(\$valueSet[\$this->$clo])) {
+ throw new PropelException('Unknown stored enum key: ' . \$this->$clo);
+ }
+ return \$valueSet[\$this->$clo];";
+ }
+
+ /**
* Adds a tester method for an array column.
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
@@ -1619,6 +1662,38 @@ protected function addRemoveArrayElement(&$script, Column $col)
}
/**
+ * Adds a setter for Enum columns.
+ * @param string &$script The script will be modified in this method.
+ * @param Column $col The current column.
+ * @see parent::addColumnMutators()
+ */
+ protected function addEnumMutator(&$script, Column $col)
+ {
+ $clo = strtolower($col->getName());
+ $this->addMutatorOpen($script, $col);
+
+ $script .= "
+ if (\$v !== null) {
+ \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . ");
+ if (!in_array(\$v, \$valueSet)) {
+ throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$v));
+ }
+ \$v = array_search(\$v, \$valueSet);
+ }
+
+ if (\$this->$clo !== \$v";
+ if (($def = $col->getDefaultValue()) !== null && !$def->isExpression()) {
+ $script .= " || \$this->isNew()";
+ }
+ $script .= ") {
+ \$this->$clo = \$v;
+ \$this->modifiedColumns[] = ".$this->getColumnConstant($col).";
+ }
+";
+ $this->addMutatorClose($script, $col);
+ }
+
+ /**
* Adds setter method for "normal" columns.
* @param string &$script The script will be modified in this method.
* @param Column $col The current column.
View
64 generator/lib/builder/om/PHP5PeerBuilder.php
@@ -234,6 +234,10 @@ protected function addConstantsAndAttributes(&$script)
$this->addFieldNamesAttribute($script);
$this->addFieldKeysAttribute($script);
+
+ if ($this->getTable()->hasEnumColumns()) {
+ $this->addEnumColumnAttributes($script);
+ }
}
/**
@@ -346,6 +350,27 @@ protected function addFieldKeysAttribute(&$script)
";
} // addFielKeysAttribute
+ /**
+ * Adds the valueSet attributes for ENUM columns.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addEnumColumnAttributes(&$script)
+ {
+ $script .= "
+ /** The enumerated values for this table */
+ protected static \$enumValueSets = array(
+";
+ foreach ($this->getTable()->getColumns() as $col) {
+ if ($col->isEnumType()) {
+ $script .= "
+ self::" . $this->getColumnName($col) ." => " . var_export($col->getValueSet(), true) . ",
+";
+ }
+ }
+ $script .= "
+ );
+";
+ }
protected function addGetFieldNames(&$script)
{
@@ -396,6 +421,45 @@ static public function translateFieldName(\$name, \$fromType, \$toType)
} // addTranslateFieldName()
/**
+ * Adds the getValueSets() method.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addGetValueSets(&$script)
+ {
+ $this->declareClassFromBuilder($this->getTableMapBuilder());
+ $script .= "
+ /**
+ * Gets the list of values for all ENUM columns
+ * @return array
+ */
+ public static function getValueSets()
+ {
+ return self::\$enumValueSets;
+ }
+";
+ }
+
+ /**
+ * Adds the getValueSet() method.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addGetValueSet(&$script)
+ {
+ $this->declareClassFromBuilder($this->getTableMapBuilder());
+ $script .= "
+ /**
+ * Gets the list of values for an ENUM column
+ * @return array list of possible values for the column
+ */
+ public static function getValueSet(\$colname)
+ {
+ \$valueSet = self::\$enumValueSets[\$colname];
+ return \$valueSet;
+ }
+";
+ }
+
+ /**
* Adds the buildTableMap() method.
* @param string &$script The script will be modified in this method.
*/
View
5 generator/lib/builder/om/PeerBuilder.php
@@ -141,6 +141,11 @@ protected function addClassBody(&$script)
$this->addTranslateFieldName($script);
$this->addGetFieldNames($script);
+
+ if ($table->hasEnumColumns()) {
+ $this->addGetValueSets($script);
+ $this->addGetValueSet($script);
+ }
if (!$table->isAlias()) {
$this->addAlias($script); // alias() utility method (deprecated?)
View
33 generator/lib/model/Column.php
@@ -89,6 +89,11 @@ class Column extends XMLElement
/** class name to do input validation on this column */
private $inputValidator = null;
+
+ /**
+ * @var stores the possible values of an ENUM column
+ */
+ protected $valueSet = array();
/**
* @var Domain The domain object associated with this Column.
@@ -166,7 +171,7 @@ protected function setupObject()
}
// Accessor visibility
- if ($this->getAttribute('accessorVisibility', null) !== null) {
+ if ($this->getAttribute('accessorVisibility', null) !== null) {
$this->setAccessorVisibility($this->getAttribute('accessorVisibility'));
} elseif ($this->getTable()->getAttribute('defaultAccessorVisibility', null) !== null) {
$this->setAccessorVisibility($this->getTable()->getAttribute('defaultAccessorVisibility'));
@@ -177,7 +182,7 @@ protected function setupObject()
}
// Mutator visibility
- if ($this->getAttribute('mutatorVisibility', null) !== null) {
+ if ($this->getAttribute('mutatorVisibility', null) !== null) {
$this->setMutatorVisibility($this->getAttribute('mutatorVisibility'));
} elseif ($this->getTable()->getAttribute('defaultMutatorVisibility', null) !== null) {
$this->setMutatorVisibility($this->getTable()->getAttribute('defaultMutatorVisibility'));
@@ -225,6 +230,12 @@ protected function setupObject()
} elseif ($this->getAttribute("defaultExpr") !== null) {
$this->getDomain()->setDefaultValue(new ColumnDefaultValue($this->getAttribute("defaultExpr"), ColumnDefaultValue::TYPE_EXPR));
}
+
+ if ($this->getAttribute('valueSet', null) !== null) {
+ $valueSet = explode(',', $this->getAttribute("valueSet"));
+ $valueSet = array_map('trim', $valueSet);
+ $this->valueSet = $valueSet;
+ }
$this->inheritanceType = $this->getAttribute("inheritance");
$this->isInheritance = ($this->inheritanceType !== null
@@ -874,6 +885,24 @@ public function isTemporalType()
{
return PropelTypes::isTemporalType($this->getType());
}
+
+ /**
+ * Utility method to know whether column is an ENUM column.
+ * @return boolean
+ */
+ public function isEnumType()
+ {
+ return $this->getType() == PropelTypes::ENUM;
+ }
+
+ /**
+ * Returns the list of possible values for an ENUM column
+ * @return array
+ */
+ public function getValueSet()
+ {
+ return $this->valueSet;
+ }
/**
* @see XMLElement::appendXml(DOMNode)
View
5 generator/lib/model/PropelTypes.php
@@ -45,6 +45,7 @@ class PropelTypes
const BOOLEAN_EMU = "BOOLEAN_EMU";
const OBJECT = "OBJECT";
const PHP_ARRAY = "ARRAY";
+ const ENUM = "ENUM";
private static $TEXT_TYPES = array(
self::CHAR, self::VARCHAR, self::LONGVARCHAR, self::CLOB, self::DATE, self::TIME, self::TIMESTAMP, self::BU_DATE, self::BU_TIMESTAMP
@@ -93,6 +94,7 @@ class PropelTypes
const BOOLEAN_EMU_NATIVE_TYPE = "boolean";
const OBJECT_NATIVE_TYPE = "";
const PHP_ARRAY_NATIVE_TYPE = "array";
+ const ENUM_NATIVE_TYPE = "string";
/**
* Mapping between Propel types and PHP native types.
@@ -127,6 +129,7 @@ class PropelTypes
self::BOOLEAN_EMU => self::BOOLEAN_EMU_NATIVE_TYPE,
self::OBJECT => self::OBJECT_NATIVE_TYPE,
self::PHP_ARRAY => self::PHP_ARRAY_NATIVE_TYPE,
+ self::ENUM => self::ENUM_NATIVE_TYPE,
);
/**
@@ -160,6 +163,7 @@ class PropelTypes
self::BOOLEAN_EMU => self::BOOLEAN_EMU,
self::OBJECT => self::OBJECT,
self::PHP_ARRAY => self::PHP_ARRAY,
+ self::ENUM => self::ENUM,
// These are pre-epoch dates, which we need to map to String type
// since they cannot be properly handled using strtotime() -- or even numeric
// timestamps on Windows.
@@ -199,6 +203,7 @@ class PropelTypes
self::BOOLEAN_EMU => PDO::PARAM_INT,
self::OBJECT => PDO::PARAM_STR,
self::PHP_ARRAY => PDO::PARAM_STR,
+ self::ENUM => PDO::PARAM_INT,
// These are pre-epoch dates, which we need to map to String type
// since they cannot be properly handled using strtotime() -- or even numeric
View
14 generator/lib/model/Table.php
@@ -1365,6 +1365,20 @@ public function getNumLazyLoadColumns()
}
return $count;
}
+
+ /**
+ * Checks whether one of the columns is of type ENUM
+ * @return boolean
+ */
+ public function hasEnumColumns()
+ {
+ foreach ($this->getColumns() as $col) {
+ if ($col->isEnumType()) {
+ return true;
+ }
+ }
+ return false;
+ }
/**
* Returns an Array containing all the validators in the table
View
1  generator/lib/platform/MssqlPlatform.php
@@ -45,6 +45,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::BLOB, "VARBINARY(MAX)"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, "VARCHAR(MAX)"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, "VARCHAR(MAX)"));
+ $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "TINYINT"));
}
public function getMaxColumnNameLength()
View
1  generator/lib/platform/MysqlPlatform.php
@@ -41,6 +41,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, "DATETIME"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, "TEXT"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, "TEXT"));
+ $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "TINYINT"));
}
/**
View
1  generator/lib/platform/OraclePlatform.php
@@ -48,6 +48,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::LONGVARBINARY, "LONG RAW"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, "NVARCHAR2", "2000"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, "NVARCHAR2", "2000"));
+ $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "NUMBER", "3", "0"));
}
View
1  generator/lib/platform/PgsqlPlatform.php
@@ -41,6 +41,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::CLOB, "TEXT"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, "TEXT"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, "TEXT"));
+ $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "INT2"));
}
public function getNativeIdMethod()
View
1  generator/lib/platform/SqlitePlatform.php
@@ -36,6 +36,7 @@ protected function initialize()
$this->setSchemaDomainMapping(new Domain(PropelTypes::CLOB, "LONGTEXT"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::OBJECT, "MEDIUMTEXT"));
$this->setSchemaDomainMapping(new Domain(PropelTypes::PHP_ARRAY, "MEDIUMTEXT"));
+ $this->setSchemaDomainMapping(new Domain(PropelTypes::ENUM, "TINYINT"));
}
/**
View
3  generator/resources/dtd/database.dtd
@@ -87,7 +87,7 @@ PHP class or method name.
| DATE | TIME | TIMESTAMP | BINARY | VARBINARY | LONGVARBINARY
| NULL | OTHER | PHP_OBJECT | DISTINCT | STRUCT | ARRAY
| BLOB | CLOB | REF | BOOLEANINT | BOOLEANCHAR
- | DOUBLE | BOOLEAN | OBJECT | ARRAY
+ | DOUBLE | BOOLEAN | OBJECT | ARRAY | ENUM
) "VARCHAR"
phpType CDATA #IMPLIED
sqlType CDATA #IMPLIED
@@ -103,6 +103,7 @@ PHP class or method name.
description CDATA #IMPLIED
lazyLoad (true|false) "false"
primaryString (true|false) "false"
+ valueSet CDATA #IMPLIED
>
<!ELEMENT inheritance EMPTY>
View
8 generator/resources/xsd/database.xsd
@@ -50,6 +50,7 @@
<xs:enumeration value="BOOLEAN"/>
<xs:enumeration value="OBJECT"/>
<xs:enumeration value="ARRAY"/>
+ <xs:enumeration value="ENUM"/>
</xs:restriction>
</xs:simpleType>
@@ -480,6 +481,13 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
+ <xs:attribute name="valueSet" type="xs:string" use="optional">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+ The list of values for an ENUM column, separated by commas
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
<xs:complexType name="foreign-key">
View
4 runtime/lib/util/PropelColumnTypes.php
@@ -47,7 +47,8 @@ class PropelColumnTypes
BOOLEAN = "BOOLEAN",
BOOLEAN_EMU = "BOOLEAN_EMU",
OBJECT = "OBJECT",
- PHP_ARRAY = "ARRAY";
+ PHP_ARRAY = "ARRAY",
+ ENUM = "ENUM";
private static $propelToPdoMap = array(
self::CHAR => PDO::PARAM_STR,
@@ -77,6 +78,7 @@ class PropelColumnTypes
self::BOOLEAN_EMU => PDO::PARAM_INT,
self::OBJECT => PDO::PARAM_STR,
self::PHP_ARRAY => PDO::PARAM_STR,
+ self::ENUM => PDO::PARAM_INT,
);
/**
View
15 test/testsuite/generator/builder/om/GeneratedObjectArrayColumnTypeTest.php
@@ -28,9 +28,6 @@ public function setUp()
<table name="complex_column_type_entity_2">
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="tags" type="ARRAY" />
- </table>
- <table name="complex_column_type_entity_3">
- <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="value_set" type="ARRAY" />
</table>
</database>
@@ -47,11 +44,11 @@ public function testActiveRecordMethods()
$this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'addTag'));
$this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'removeTag'));
// only plural column names get a tester, an adder, and a remover method
- $this->assertTrue(method_exists('ComplexColumnTypeEntity3', 'getValueSet'));
- $this->assertFalse(method_exists('ComplexColumnTypeEntity3', 'hasValueSet'));
- $this->assertTrue(method_exists('ComplexColumnTypeEntity3', 'setValueSet'));
- $this->assertFalse(method_exists('ComplexColumnTypeEntity3', 'addValueSet'));
- $this->assertFalse(method_exists('ComplexColumnTypeEntity3', 'removeValueSet'));
+ $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'getValueSet'));
+ $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'hasValueSet'));
+ $this->assertTrue(method_exists('ComplexColumnTypeEntity2', 'setValueSet'));
+ $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'addValueSet'));
+ $this->assertFalse(method_exists('ComplexColumnTypeEntity2', 'removeValueSet'));
}
public function testGetterDefaultValue()
@@ -121,7 +118,7 @@ public function testRemover()
$this->assertEquals(array(12, 34), $e->getTags());
}
- public function testValueIsPersisted($value='')
+ public function testValueIsPersisted()
{
$e = new ComplexColumnTypeEntity2();
$value = array('foo', 1234);
View
102 test/testsuite/generator/builder/om/GeneratedObjectEnumColumnTypeTest.php
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ * This file is part of the Propel package.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @license MIT License
+ */
+
+require_once 'PHPUnit/Framework.php';
+require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
+require_once dirname(__FILE__) . '/../../../../../runtime/lib/Propel.php';
+
+/**
+ * Tests the generated objects for enum column types accessor & mutator
+ *
+ * @author Francois Zaninotto
+ * @package generator.builder.om
+ */
+class GeneratedObjectObjectEnumTypeTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ if (!class_exists('ComplexColumnTypeEntity13')) {
+ $schema = <<<EOF
+<database name="generated_object_complex_type_test_13">
+ <table name="complex_column_type_entity_13">
+ <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
+ <column name="bar" type="ENUM" valueSet="foo, bar, baz, 1, 4,(, foo bar " />
+ </table>
+</database>
+EOF;
+ PropelQuickBuilder::buildSchema($schema);
+ // ok this is hackish but it makes testing of getter and sette rindependent of each other
+ $publicAccessorCode = <<<EOF
+class PublicComplexColumnTypeEntity13 extends ComplexColumnTypeEntity13
+{
+ public \$bar;
+}
+EOF;
+ eval($publicAccessorCode);
+ }
+ }
+
+ public function testGetter()
+ {
+ $this->assertTrue(method_exists('ComplexColumnTypeEntity13', 'getBar'));
+ $e = new ComplexColumnTypeEntity13();
+ $this->assertNull($e->getBar());
+ $e = new PublicComplexColumnTypeEntity13();
+ $e->bar = 0;
+ $this->assertEquals('foo', $e->getBar());
+ $e->bar = 3;
+ $this->assertEquals('1', $e->getBar());
+ $e->bar = 6;
+ $this->assertEquals('foo bar', $e->getBar());
+ }
+
+ /**
+ * @expectedException PropelException
+ */
+ public function testGetterThrowsExceptionOnUnknownKey()
+ {
+ $e = new PublicComplexColumnTypeEntity13();
+ $e->bar = 156;
+ $e->getBar();
+ }
+
+ public function testSetter()
+ {
+ $this->assertTrue(method_exists('ComplexColumnTypeEntity13', 'setBar'));
+ $e = new PublicComplexColumnTypeEntity13();
+ $e->setBar('foo');
+ $this->assertEquals(0, $e->bar);
+ $e->setBar(1);
+ $this->assertEquals(3, $e->bar);
+ $e->setBar('1');
+ $this->assertEquals(3, $e->bar);
+ $e->setBar('foo bar');
+ $this->assertEquals(6, $e->bar);
+ }
+
+ /**
+ * @expectedException PropelException
+ */
+ public function testSetterThrowsExceptionOnUnknownValue()
+ {
+ $e = new ComplexColumnTypeEntity13();
+ $e->setBar('bazz');
+ }
+
+ public function testValueIsPersisted()
+ {
+ $e = new ComplexColumnTypeEntity13();
+ $e->setBar('baz');
+ $e->save();
+ ComplexColumnTypeEntity13Peer::clearInstancePool();
+ $e = ComplexColumnTypeEntity13Query::create()->findOne();
+ $this->assertEquals('baz', $e->getBar());
+ }
+}
View
49 test/testsuite/generator/builder/om/GeneratedPeerEnumColumnTypeTest.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * This file is part of the Propel package.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @license MIT License
+ */
+
+require_once 'PHPUnit/Framework.php';
+require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
+require_once dirname(__FILE__) . '/../../../../../runtime/lib/Propel.php';
+
+/**
+ * Tests the generated Peer classes for enum column type constants
+ *
+ * @author Francois Zaninotto
+ * @package generator.builder.om
+ */
+class GeneratedObjectObjectEnumTypeTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ if (!class_exists('ComplexColumnTypeEntity103Peer')) {
+ $schema = <<<EOF
+<database name="generated_object_complex_type_test_103">
+ <table name="complex_column_type_entity_103">
+ <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
+ <column name="bar" type="ENUM" valueSet="foo, bar, baz, 1, 4,(, foo bar " />
+ </table>
+</database>
+EOF;
+ PropelQuickBuilder::buildSchema($schema);
+ }
+ }
+
+ public function testGetValueSets()
+ {
+ $expected = array(ComplexColumnTypeEntity103Peer::BAR => array('foo', 'bar', 'baz', '1', '4', '(', 'foo bar'));
+ $this->assertEquals($expected, ComplexColumnTypeEntity103Peer::getValueSets());
+ }
+
+ public function testGetValueSet()
+ {
+ $expected = array('foo', 'bar', 'baz', '1', '4', '(', 'foo bar');
+ $this->assertEquals($expected, ComplexColumnTypeEntity103Peer::getValueSet(ComplexColumnTypeEntity103Peer::BAR));
+ }
+}
View
5 test/testsuite/generator/builder/om/GeneratedQueryArrayColumnTypeTest.php
@@ -28,9 +28,6 @@ public function setUp()
<table name="complex_column_type_entity_11">
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="tags" type="ARRAY" />
- </table>
- <table name="complex_column_type_entity_12">
- <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="value_set" type="ARRAY" />
</table>
</database>
@@ -55,7 +52,7 @@ public function testActiveQueryMethods()
$this->assertTrue(method_exists('ComplexColumnTypeEntity11Query', 'filterByTags'));
$this->assertTrue(method_exists('ComplexColumnTypeEntity11Query', 'filterByTag'));
// only plural column names get a singular filter
- $this->assertTrue(method_exists('ComplexColumnTypeEntity12Query', 'filterByValueSet'));
+ $this->assertTrue(method_exists('ComplexColumnTypeEntity11Query', 'filterByValueSet'));
}
public function testColumnHydration()
Please sign in to comment.
Something went wrong with that request. Please try again.