/** * column definition * * @param string $columnName Column name * @param string $type Type generic * @param array $options Options * * @return string */ public function columnDefinition($columnName, $type, $options = array()) { $col = new Phigrate_Adapter_Mysql_ColumnDefinition($this, $columnName, $type, $options); return $col->__toString(); }
public function testToSqlAndToString() { $expected = '`last_name` varchar(32) NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'last_name', 'string', array('limit' => 32)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`last_name` varchar(255) NOT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'last_name', 'string', array('null' => false)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`last_name` varchar(255) NOT NULL DEFAULT \'abc\''; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'last_name', 'string', array('default' => 'abc', 'null' => false)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`last_name` varchar(5) NOT NULL DEFAULT \'abc\''; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'last_name', 'string', array('limit' => 5, 'default' => 'abc')); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`created_at` datetime NOT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'created_at', 'datetime', array('null' => false)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`id` int(11) UNSIGNED NOT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'id', 'integer', array('primary_key' => true, 'unsigned' => true)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`phone` varchar(10) NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'phone', 'string', array('limit' => 10)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`price` decimal(2) NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'price', 'decimal', array('precision' => 2)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`price` decimal(2, 4) NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'price', 'decimal', array('precision' => 2, 'scale' => 4)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`happy` tinyint(1) NOT NULL DEFAULT \'1\''; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'happy', 'boolean', array('default' => true)); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`licence` text NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'licence', 'text', array()); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); $expected = '`avatar` blob NULL DEFAULT NULL'; $c = new Phigrate_Adapter_Mysql_ColumnDefinition($this->_adapter, 'avatar', 'binary', array()); $this->assertEquals($expected, $c->toSql()); $this->assertEquals($expected, $c->__toString()); }