Skip to content
Permalink
Browse files

Making Table::columnType() a setter too

  • Loading branch information...
lorenzo committed Jul 6, 2014
1 parent 804ad32 commit 669e5c9ce9f0f0ccf3d4270ef6b4499e5b0be524
Showing with 29 additions and 2 deletions.
  1. +12 −2 src/Database/Schema/Table.php
  2. +17 −0 tests/TestCase/Database/Schema/TableTest.php
@@ -224,6 +224,11 @@ class Table {
*/
const ACTION_RESTRICT = 'restrict';
/**
* Foreign key restrict default
*
* @var string
*/
const ACTION_SET_DEFAULT = 'setDefault';
/**
@@ -312,15 +317,20 @@ public function column($name) {
}
/**
* Convenience method for getting the type of a given column.
* Sets the type of a column, or returns its current type
* if none is passed.
*
* @param string $name The column to get the type of.
* @param string $type The type to set the column to.
* @return string|null Either the column type or null.
*/
public function columnType($name) {
public function columnType($name, $type = null) {
if (!isset($this->_columns[$name])) {
return null;
}
if ($type !== null) {
$this->_columns[$name]['type'] = $type;
}
return $this->_columns[$name]['type'];
}
@@ -78,6 +78,23 @@ public function testColumnType() {
$this->assertNull($table->columnType('not there'));
}
/**
* Test columnType setter method
*
* @return void
*/
public function testColumnTypeSet() {
$table = new Table('articles');
$table->addColumn('title', [
'type' => 'string',
'length' => 25,
'null' => false
]);
$this->assertEquals('string', $table->columnType('title'));
$table->columnType('title', 'json');
$this->assertEquals('json', $table->columnType('title'));
}
/**
* Attribute keys should be filtered and have defaults set.
*

0 comments on commit 669e5c9

Please sign in to comment.
You can’t perform that action at this time.