@@ -81,21 +81,19 @@ public function testCreateTable()
8181 {
8282 $ this ->forge ->dropTable ('forge_test_table ' , true );
8383
84- $ this ->forge ->addField (
85- [
86- 'id ' => [
87- 'type ' => 'INTEGER ' ,
88- 'constraint ' => 11 ,
89- 'unsigned ' => true ,
90- 'auto_increment ' => true ,
91- ],
92- 'mobile ' => [
93- 'type ' => 'INTEGER ' ,
94- 'constraint ' => 10 ,
95- 'unsigned ' => true ,
96- ],
97- ]
98- );
84+ $ this ->forge ->addField ([
85+ 'id ' => [
86+ 'type ' => 'INTEGER ' ,
87+ 'constraint ' => 11 ,
88+ 'unsigned ' => true ,
89+ 'auto_increment ' => true ,
90+ ],
91+ 'mobile ' => [
92+ 'type ' => 'INTEGER ' ,
93+ 'constraint ' => 10 ,
94+ 'unsigned ' => true ,
95+ ],
96+ ]);
9997
10098 $ unsignedAttributes = [
10199 'INTEGER ' ,
@@ -141,15 +139,15 @@ public function testCreateTableWithArrayFieldConstraints()
141139 {
142140 $ this ->forge ->dropTable ('forge_array_constraint ' , true );
143141 $ this ->forge ->addField ([
144- 'status ' => [
145- 'type ' => 'ENUM ' ,
146- 'constraint ' => [
147- 'sad ' ,
148- 'ok ' ,
149- 'happy ' ,
150- ],
151- ],
152- ]);
142+ 'status ' => [
143+ 'type ' => 'ENUM ' ,
144+ 'constraint ' => [
145+ 'sad ' ,
146+ 'ok ' ,
147+ 'happy ' ,
148+ ],
149+ ],
150+ ]);
153151 $ this ->forge ->createTable ('forge_array_constraint ' );
154152
155153 $ fields = $ this ->db ->getFieldData ('forge_array_constraint ' );
@@ -288,37 +286,33 @@ public function testForeignKey()
288286 $ attributes = ['ENGINE ' => 'InnoDB ' ];
289287 }
290288
291- $ this ->forge ->addField (
292- [
293- 'id ' => [
294- 'type ' => 'INTEGER ' ,
295- 'constraint ' => 11 ,
296- ],
297- 'name ' => [
298- 'type ' => 'VARCHAR ' ,
299- 'constraint ' => 255 ,
300- ],
301- ]
302- );
289+ $ this ->forge ->addField ([
290+ 'id ' => [
291+ 'type ' => 'INTEGER ' ,
292+ 'constraint ' => 11 ,
293+ ],
294+ 'name ' => [
295+ 'type ' => 'VARCHAR ' ,
296+ 'constraint ' => 255 ,
297+ ],
298+ ]);
303299 $ this ->forge ->addKey ('id ' , true );
304300 $ this ->forge ->createTable ('forge_test_users ' , true , $ attributes );
305301
306- $ this ->forge ->addField (
307- [
308- 'id ' => [
309- 'type ' => 'INTEGER ' ,
310- 'constraint ' => 11 ,
311- ],
312- 'users_id ' => [
313- 'type ' => 'INTEGER ' ,
314- 'constraint ' => 11 ,
315- ],
316- 'name ' => [
317- 'type ' => 'VARCHAR ' ,
318- 'constraint ' => 255 ,
319- ],
320- ]
321- );
302+ $ this ->forge ->addField ([
303+ 'id ' => [
304+ 'type ' => 'INTEGER ' ,
305+ 'constraint ' => 11 ,
306+ ],
307+ 'users_id ' => [
308+ 'type ' => 'INTEGER ' ,
309+ 'constraint ' => 11 ,
310+ ],
311+ 'name ' => [
312+ 'type ' => 'VARCHAR ' ,
313+ 'constraint ' => 255 ,
314+ ],
315+ ]);
322316 $ this ->forge ->addKey ('id ' , true );
323317 $ this ->forge ->addForeignKey ('users_id ' , 'forge_test_users ' , 'id ' , 'CASCADE ' , 'CASCADE ' );
324318
@@ -353,37 +347,33 @@ public function testForeignKeyFieldNotExistException()
353347 $ attributes = ['ENGINE ' => 'InnoDB ' ];
354348 }
355349
356- $ this ->forge ->addField (
357- [
358- 'id ' => [
359- 'type ' => 'INTEGER ' ,
360- 'constraint ' => 11 ,
361- ],
362- 'name ' => [
363- 'type ' => 'VARCHAR ' ,
364- 'constraint ' => 255 ,
365- ],
366- ]
367- );
350+ $ this ->forge ->addField ([
351+ 'id ' => [
352+ 'type ' => 'INTEGER ' ,
353+ 'constraint ' => 11 ,
354+ ],
355+ 'name ' => [
356+ 'type ' => 'VARCHAR ' ,
357+ 'constraint ' => 255 ,
358+ ],
359+ ]);
368360 $ this ->forge ->addKey ('id ' , true );
369361 $ this ->forge ->createTable ('forge_test_users ' , true , $ attributes );
370362
371- $ this ->forge ->addField (
372- [
373- 'id ' => [
374- 'type ' => 'INTEGER ' ,
375- 'constraint ' => 11 ,
376- ],
377- 'users_id ' => [
378- 'type ' => 'INTEGER ' ,
379- 'constraint ' => 11 ,
380- ],
381- 'name ' => [
382- 'type ' => 'VARCHAR ' ,
383- 'constraint ' => 255 ,
384- ],
385- ]
386- );
363+ $ this ->forge ->addField ([
364+ 'id ' => [
365+ 'type ' => 'INTEGER ' ,
366+ 'constraint ' => 11 ,
367+ ],
368+ 'users_id ' => [
369+ 'type ' => 'INTEGER ' ,
370+ 'constraint ' => 11 ,
371+ ],
372+ 'name ' => [
373+ 'type ' => 'VARCHAR ' ,
374+ 'constraint ' => 255 ,
375+ ],
376+ ]);
387377 $ this ->forge ->addKey ('id ' , true );
388378 $ this ->forge ->addForeignKey ('user_id ' , 'forge_test_users ' , 'id ' , 'CASCADE ' , 'CASCADE ' );
389379
@@ -404,32 +394,32 @@ public function testDropForeignKey()
404394 }
405395
406396 $ this ->forge ->addField ([
407- 'id ' => [
408- 'type ' => 'INTEGER ' ,
409- 'constraint ' => 11 ,
410- ],
411- 'name ' => [
412- 'type ' => 'VARCHAR ' ,
413- 'constraint ' => 255 ,
414- ],
415- ]);
397+ 'id ' => [
398+ 'type ' => 'INTEGER ' ,
399+ 'constraint ' => 11 ,
400+ ],
401+ 'name ' => [
402+ 'type ' => 'VARCHAR ' ,
403+ 'constraint ' => 255 ,
404+ ],
405+ ]);
416406 $ this ->forge ->addKey ('id ' , true );
417407 $ this ->forge ->createTable ('forge_test_users ' , true , $ attributes );
418408
419409 $ this ->forge ->addField ([
420- 'id ' => [
421- 'type ' => 'INTEGER ' ,
422- 'constraint ' => 11 ,
423- ],
424- 'users_id ' => [
425- 'type ' => 'INTEGER ' ,
426- 'constraint ' => 11 ,
427- ],
428- 'name ' => [
429- 'type ' => 'VARCHAR ' ,
430- 'constraint ' => 255 ,
431- ],
432- ]);
410+ 'id ' => [
411+ 'type ' => 'INTEGER ' ,
412+ 'constraint ' => 11 ,
413+ ],
414+ 'users_id ' => [
415+ 'type ' => 'INTEGER ' ,
416+ 'constraint ' => 11 ,
417+ ],
418+ 'name ' => [
419+ 'type ' => 'VARCHAR ' ,
420+ 'constraint ' => 255 ,
421+ ],
422+ ]);
433423 $ this ->forge ->addKey ('id ' , true );
434424 $ this ->forge ->addForeignKey ('users_id ' , 'forge_test_users ' , 'id ' , 'CASCADE ' , 'CASCADE ' );
435425
@@ -449,16 +439,14 @@ public function testAddColumn()
449439 {
450440 $ this ->forge ->dropTable ('forge_test_table ' , true );
451441
452- $ this ->forge ->addField (
453- [
454- 'id ' => [
455- 'type ' => 'INTEGER ' ,
456- 'constraint ' => 11 ,
457- 'unsigned ' => false ,
458- 'auto_increment ' => true ,
459- ],
460- ]
461- );
442+ $ this ->forge ->addField ([
443+ 'id ' => [
444+ 'type ' => 'INTEGER ' ,
445+ 'constraint ' => 11 ,
446+ 'unsigned ' => false ,
447+ 'auto_increment ' => true ,
448+ ],
449+ ]);
462450
463451 $ this ->forge ->addKey ('id ' , true );
464452 $ this ->forge ->createTable ('forge_test_table ' );
@@ -474,8 +462,8 @@ public function testAddColumn()
474462 $ this ->forge ->addColumn ('forge_test_table ' , $ newField );
475463
476464 $ fieldNames = $ this ->db ->table ('forge_test_table ' )
477- ->get ()
478- ->getFieldNames ();
465+ ->get ()
466+ ->getFieldNames ();
479467
480468 $ this ->forge ->dropTable ('forge_test_table ' , true );
481469
@@ -715,4 +703,27 @@ public function testConnectWithArrayGroup()
715703
716704 $ this ->assertInstanceOf (Forge::class, $ forge );
717705 }
706+
707+ /**
708+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/1983
709+ */
710+ public function testDropTableSuccess ()
711+ {
712+ // Add an index to user table so we have
713+ // something to work with
714+ $ this ->forge ->addField ([
715+ 'id ' => [
716+ 'type ' => 'INTEGER ' ,
717+ 'constraint ' => 3 ,
718+ ],
719+ ]);
720+ $ this ->forge ->addKey ('id ' );
721+ $ this ->forge ->createTable ('droptest ' );
722+
723+ $ this ->assertCount (1 , $ this ->db ->getIndexData ('droptest ' ));
724+
725+ $ this ->forge ->dropTable ('droptest ' , true );
726+
727+ $ this ->assertCount (0 , $ this ->db ->getIndexData ('droptest ' ));
728+ }
718729}
0 commit comments