Skip to content

Commit f9c953c

Browse files
committed
test: add test for Fore::modifyColumn() and null
1 parent 33c8e49 commit f9c953c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/system/Database/Live/ForgeTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Test\DatabaseTestTrait;
1818
use Config\Database;
1919
use RuntimeException;
20+
use stdClass;
2021
use Tests\Support\Database\Seeds\CITestSeeder;
2122

2223
/**
@@ -1281,6 +1282,46 @@ public function testModifyColumnRename()
12811282
$this->forge->dropTable('forge_test_three', true);
12821283
}
12831284

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+
12841325
public function testConnectWithArrayGroup()
12851326
{
12861327
$group = config('Database');

0 commit comments

Comments
 (0)