/** * Returns the SQL for the default value of a Column object * @return string */ public function getColumnDefaultValueDDL(Column $col) { $default = ''; $defaultValue = $col->getDefaultValue(); if (null !== $defaultValue) { $default .= 'DEFAULT '; if ($defaultValue->isExpression()) { $default .= $defaultValue->getValue(); } else { if ($col->isTextType()) { $default .= $this->quote($defaultValue->getValue()); } elseif (in_array($col->getType(), [PropelTypes::BOOLEAN, PropelTypes::BOOLEAN_EMU])) { $default .= $this->getBooleanString($defaultValue->getValue()); } elseif ($col->getType() == PropelTypes::ENUM) { $default .= array_search($defaultValue->getValue(), $col->getValueSet()); } elseif ($col->isSetType()) { $val = trim($defaultValue->getValue()); $values = []; foreach (explode(',', $val) as $v) { $values[] = trim($v); } $default .= SetColumnConverter::convertToInt($values, $col->getValueSet()); } elseif ($col->isPhpArrayType()) { $value = $this->getPhpArrayString($defaultValue->getValue()); if (null === $value) { $default = ''; } else { $default .= $value; } } else { $default .= $defaultValue->getValue(); } } } return $default; }
public function testSetType() { $domain = $this->getDomainMock(); $domain->expects($this->any())->method('getType')->will($this->returnValue('SET')); $column = new Column(); $column->setDomain($domain); $column->setType('SET'); $column->setValueSet(['FOO', 'BAR']); $this->assertSame('int', $column->getPhpType()); $this->assertTrue($column->isPhpPrimitiveType()); $this->assertTrue($column->isSetType()); $this->assertContains('FOO', $column->getValueSet()); $this->assertContains('BAR', $column->getValueSet()); }