|
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 | /**
|
@@ -825,6 +826,41 @@ public function testAddColumn()
|
825 | 826 | $this->assertSame('username', $fieldNames[1]);
|
826 | 827 | }
|
827 | 828 |
|
| 829 | + public function testAddColumnNull() |
| 830 | + { |
| 831 | + $this->forge->dropTable('forge_test_table', true); |
| 832 | + |
| 833 | + $this->forge->addField([ |
| 834 | + 'col1' => ['type' => 'VARCHAR', 'constraint' => 255], |
| 835 | + 'col2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], |
| 836 | + 'col3' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false], |
| 837 | + ]); |
| 838 | + $this->forge->createTable('forge_test_table'); |
| 839 | + |
| 840 | + $this->forge->addColumn('forge_test_table', [ |
| 841 | + 'col4' => ['type' => 'VARCHAR', 'constraint' => 255], |
| 842 | + 'col5' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], |
| 843 | + 'col6' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false], |
| 844 | + ]); |
| 845 | + |
| 846 | + $this->db->resetDataCache(); |
| 847 | + |
| 848 | + $col1 = $this->getMetaData('col1', 'forge_test_table'); |
| 849 | + $this->assertFalse($col1->nullable); |
| 850 | + $col2 = $this->getMetaData('col2', 'forge_test_table'); |
| 851 | + $this->assertTrue($col2->nullable); |
| 852 | + $col3 = $this->getMetaData('col3', 'forge_test_table'); |
| 853 | + $this->assertFalse($col3->nullable); |
| 854 | + $col4 = $this->getMetaData('col4', 'forge_test_table'); |
| 855 | + $this->assertTrue($col4->nullable); |
| 856 | + $col5 = $this->getMetaData('col5', 'forge_test_table'); |
| 857 | + $this->assertTrue($col5->nullable); |
| 858 | + $col6 = $this->getMetaData('col6', 'forge_test_table'); |
| 859 | + $this->assertFalse($col6->nullable); |
| 860 | + |
| 861 | + $this->forge->dropTable('forge_test_table', true); |
| 862 | + } |
| 863 | + |
828 | 864 | public function testAddFields()
|
829 | 865 | {
|
830 | 866 | $tableName = 'forge_test_fields';
|
@@ -1281,6 +1317,17 @@ public function testModifyColumnRename()
|
1281 | 1317 | $this->forge->dropTable('forge_test_three', true);
|
1282 | 1318 | }
|
1283 | 1319 |
|
| 1320 | + private function getMetaData(string $column, string $table): stdClass |
| 1321 | + { |
| 1322 | + $fields = $this->db->getFieldData($table); |
| 1323 | + |
| 1324 | + return $fields[array_search( |
| 1325 | + $column, |
| 1326 | + array_column($fields, 'name'), |
| 1327 | + true |
| 1328 | + )]; |
| 1329 | + } |
| 1330 | + |
1284 | 1331 | public function testConnectWithArrayGroup()
|
1285 | 1332 | {
|
1286 | 1333 | $group = config('Database');
|
|
0 commit comments