@@ -488,6 +488,33 @@ public function testAddColumnWithDefaultEmptyString()
488
488
$ this ->assertEquals ("'' " , $ rows [1 ]['dflt_value ' ]);
489
489
}
490
490
491
+ public function irregularCreateTableProvider ()
492
+ {
493
+ return [
494
+ ["CREATE TABLE \"users \"\n( `id` INTEGER NOT NULL ) " , ['id ' , 'foo ' ]],
495
+ ['CREATE TABLE users ( id INTEGER NOT NULL ) ' , ['id ' , 'foo ' ]],
496
+ ["CREATE TABLE [users] \n( \nid INTEGER NOT NULL) " , ['id ' , 'foo ' ]],
497
+ ["CREATE TABLE \"users \" ([id] \n INTEGER NOT NULL \n, \"bar \" INTEGER) " , ['id ' , 'bar ' , 'foo ' ]],
498
+ ];
499
+ }
500
+
501
+ /**
502
+ * @dataProvider irregularCreateTableProvider
503
+ */
504
+ public function testAddColumnToIrregularCreateTableStatements (string $ createTableSql , array $ expectedColumns ): void
505
+ {
506
+ $ this ->adapter ->execute ($ createTableSql );
507
+ $ table = new \Phinx \Db \Table ('users ' , [], $ this ->adapter );
508
+ $ table ->addColumn ('foo ' , 'string ' );
509
+ $ table ->update ();
510
+
511
+ $ columns = $ this ->adapter ->getColumns ('users ' );
512
+ $ columnCount = count ($ columns );
513
+ for ($ i = 0 ; $ i < $ columnCount ; $ i ++) {
514
+ $ this ->assertEquals ($ expectedColumns [$ i ], $ columns [$ i ]->getName ());
515
+ }
516
+ }
517
+
491
518
public function testAddDoubleColumn ()
492
519
{
493
520
$ table = new \Phinx \Db \Table ('table1 ' , [], $ this ->adapter );
0 commit comments