|
17 | 17 | use CodeIgniter\Test\DatabaseTestTrait; |
18 | 18 | use Config\Database; |
19 | 19 | use RuntimeException; |
| 20 | +use stdClass; |
20 | 21 | use Tests\Support\Database\Seeds\CITestSeeder; |
21 | 22 |
|
22 | 23 | /** |
@@ -1281,6 +1282,46 @@ public function testModifyColumnRename() |
1281 | 1282 | $this->forge->dropTable('forge_test_three', true); |
1282 | 1283 | } |
1283 | 1284 |
|
| 1285 | + public function testModifyColumnNull() |
| 1286 | + { |
| 1287 | + $this->forge->dropTable('forge_test_modify', true); |
| 1288 | + |
| 1289 | + $this->forge->addField([ |
| 1290 | + 'col1' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], |
| 1291 | + 'col2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], |
| 1292 | + 'col3' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], |
| 1293 | + ]); |
| 1294 | + $this->forge->createTable('forge_test_modify'); |
| 1295 | + |
| 1296 | + $this->forge->modifyColumn('forge_test_modify', [ |
| 1297 | + 'col1' => ['type' => 'VARCHAR', 'constraint' => 1], |
| 1298 | + 'col2' => ['type' => 'VARCHAR', 'constraint' => 1, 'null' => true], |
| 1299 | + 'col3' => ['type' => 'VARCHAR', 'constraint' => 1, 'null' => false], |
| 1300 | + ]); |
| 1301 | + |
| 1302 | + $this->db->resetDataCache(); |
| 1303 | + |
| 1304 | + $col1 = $this->getMetaData('col1'); |
| 1305 | + $this->assertTrue($col1->nullable); |
| 1306 | + $col2 = $this->getMetaData('col2'); |
| 1307 | + $this->assertTrue($col2->nullable); |
| 1308 | + $col3 = $this->getMetaData('col3'); |
| 1309 | + $this->assertFalse($col3->nullable); |
| 1310 | + |
| 1311 | + $this->forge->dropTable('forge_test_modify', true); |
| 1312 | + } |
| 1313 | + |
| 1314 | + private function getMetaData(string $column): stdClass |
| 1315 | + { |
| 1316 | + $fields = $this->db->getFieldData('forge_test_modify'); |
| 1317 | + |
| 1318 | + return $fields[array_search( |
| 1319 | + $column, |
| 1320 | + array_column($fields, 'name'), |
| 1321 | + true |
| 1322 | + )]; |
| 1323 | + } |
| 1324 | + |
1284 | 1325 | public function testConnectWithArrayGroup() |
1285 | 1326 | { |
1286 | 1327 | $group = config('Database'); |
|
0 commit comments