File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
tests/TestCase/Database/Schema Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ class Table {
224
224
*/
225
225
const ACTION_RESTRICT = 'restrict ' ;
226
226
227
+ /**
228
+ * Foreign key restrict default
229
+ *
230
+ * @var string
231
+ */
227
232
const ACTION_SET_DEFAULT = 'setDefault ' ;
228
233
229
234
/**
@@ -312,15 +317,20 @@ public function column($name) {
312
317
}
313
318
314
319
/**
315
- * Convenience method for getting the type of a given column.
320
+ * Sets the type of a column, or returns its current type
321
+ * if none is passed.
316
322
*
317
323
* @param string $name The column to get the type of.
324
+ * @param string $type The type to set the column to.
318
325
* @return string|null Either the column type or null.
319
326
*/
320
- public function columnType ($ name ) {
327
+ public function columnType ($ name, $ type = null ) {
321
328
if (!isset ($ this ->_columns [$ name ])) {
322
329
return null ;
323
330
}
331
+ if ($ type !== null ) {
332
+ $ this ->_columns [$ name ]['type ' ] = $ type ;
333
+ }
324
334
return $ this ->_columns [$ name ]['type ' ];
325
335
}
326
336
Original file line number Diff line number Diff line change @@ -78,6 +78,23 @@ public function testColumnType() {
78
78
$ this ->assertNull ($ table ->columnType ('not there ' ));
79
79
}
80
80
81
+ /**
82
+ * Test columnType setter method
83
+ *
84
+ * @return void
85
+ */
86
+ public function testColumnTypeSet () {
87
+ $ table = new Table ('articles ' );
88
+ $ table ->addColumn ('title ' , [
89
+ 'type ' => 'string ' ,
90
+ 'length ' => 25 ,
91
+ 'null ' => false
92
+ ]);
93
+ $ this ->assertEquals ('string ' , $ table ->columnType ('title ' ));
94
+ $ table ->columnType ('title ' , 'json ' );
95
+ $ this ->assertEquals ('json ' , $ table ->columnType ('title ' ));
96
+ }
97
+
81
98
/**
82
99
* Attribute keys should be filtered and have defaults set.
83
100
*
You can’t perform that action at this time.
0 commit comments