@@ -39,6 +39,9 @@ public function setUp()
3939
4040 public function tearDown ()
4141 {
42+ if (!empty ($ this ->adapter )) {
43+ $ this ->adapter ->disconnect ();
44+ }
4245 unset($ this ->adapter );
4346 }
4447
@@ -65,6 +68,7 @@ public function testConnectionWithInvalidCredentials()
6568 'pass ' => 'invalidpass '
6669 ];
6770
71+ $ adapter = null ;
6872 try {
6973 $ adapter = new SqlServerAdapter ($ options , new ArrayInput ([]), new NullOutput ());
7074 $ adapter ->connect ();
@@ -76,6 +80,10 @@ public function testConnectionWithInvalidCredentials()
7680 'Expected exception of type InvalidArgumentException, got ' . get_class ($ e )
7781 );
7882 $ this ->assertRegExp ('/There was a problem connecting to the database/ ' , $ e ->getMessage ());
83+ } finally {
84+ if (!empty ($ adapter )) {
85+ $ adapter ->disconnect ();
86+ }
7987 }
8088 }
8189
@@ -308,21 +316,34 @@ public function testRenamingANonExistentColumn()
308316 }
309317 }
310318
311- public function testChangeColumn ()
319+ public function testChangeColumnType ()
312320 {
313321 $ table = new \Phinx \Db \Table ('t ' , [], $ this ->adapter );
314322 $ table ->addColumn ('column1 ' , 'string ' )
315323 ->save ();
316324 $ this ->assertTrue ($ this ->adapter ->hasColumn ('t ' , 'column1 ' ));
317325 $ newColumn1 = new \Phinx \Db \Table \Column ();
318326 $ newColumn1 ->setType ('string ' );
319- $ table ->changeColumn ('column1 ' , $ newColumn1 );
327+ $ table ->changeColumn ('column1 ' , $ newColumn1 )-> save () ;
320328 $ this ->assertTrue ($ this ->adapter ->hasColumn ('t ' , 'column1 ' ));
329+ $ columns = $ this ->adapter ->getColumns ('t ' );
330+ foreach ($ columns as $ column ) {
331+ if ($ column ->getName () == 'column1 ' ) {
332+ $ this ->assertEquals ('string ' , $ column ->getType ());
333+ }
334+ }
335+ }
336+
337+ public function testChangeColumnNameAndNull ()
338+ {
339+ $ table = new \Phinx \Db \Table ('t ' , [], $ this ->adapter );
340+ $ table ->addColumn ('column1 ' , 'string ' )
341+ ->save ();
321342 $ newColumn2 = new \Phinx \Db \Table \Column ();
322343 $ newColumn2 ->setName ('column2 ' )
323- ->setType ('string ' )
324- ->setNull (true );
325- $ table ->changeColumn ('column1 ' , $ newColumn2 );
344+ ->setType ('string ' )
345+ ->setNull (true );
346+ $ table ->changeColumn ('column1 ' , $ newColumn2 )-> save () ;
326347 $ this ->assertFalse ($ this ->adapter ->hasColumn ('t ' , 'column1 ' ));
327348 $ this ->assertTrue ($ this ->adapter ->hasColumn ('t ' , 'column2 ' ));
328349 $ columns = $ this ->adapter ->getColumns ('t ' );
@@ -347,7 +368,7 @@ public function testChangeColumnDefaults()
347368 $ newColumn1
348369 ->setType ('string ' )
349370 ->setDefault ('another test ' );
350- $ table ->changeColumn ('column1 ' , $ newColumn1 );
371+ $ table ->changeColumn ('column1 ' , $ newColumn1 )-> save () ;
351372 $ this ->assertTrue ($ this ->adapter ->hasColumn ('t ' , 'column1 ' ));
352373
353374 $ columns = $ this ->adapter ->getColumns ('t ' );
@@ -363,7 +384,7 @@ public function testChangeColumnDefaultToNull()
363384 $ newColumn1
364385 ->setType ('string ' )
365386 ->setDefault (null );
366- $ table ->changeColumn ('column1 ' , $ newColumn1 );
387+ $ table ->changeColumn ('column1 ' , $ newColumn1 )-> save () ;
367388 $ columns = $ this ->adapter ->getColumns ('t ' );
368389 $ this ->assertNull ($ columns ['column1 ' ]->getDefault ());
369390 }
@@ -377,7 +398,7 @@ public function testChangeColumnDefaultToZero()
377398 $ newColumn1
378399 ->setType ('string ' )
379400 ->setDefault (0 );
380- $ table ->changeColumn ('column1 ' , $ newColumn1 );
401+ $ table ->changeColumn ('column1 ' , $ newColumn1 )-> save () ;
381402 $ columns = $ this ->adapter ->getColumns ('t ' );
382403 $ this ->assertSame (0 , $ columns ['column1 ' ]->getDefault ());
383404 }
@@ -392,34 +413,38 @@ public function testDropColumn()
392413 $ this ->assertFalse ($ this ->adapter ->hasColumn ('t ' , 'column1 ' ));
393414 }
394415
395- public function testGetColumns ()
416+ public function columnsProvider ()
417+ {
418+ return [
419+ ['column1 ' , 'string ' , ['null ' => true , 'default ' => null ]],
420+ ['column2 ' , 'integer ' , ['default ' => 0 ]],
421+ ['column3 ' , 'biginteger ' , ['default ' => 5 ]],
422+ ['column4 ' , 'text ' , ['default ' => 'text ' ]],
423+ ['column5 ' , 'float ' , []],
424+ ['column6 ' , 'decimal ' , []],
425+ ['column7 ' , 'time ' , []],
426+ ['column8 ' , 'date ' , []],
427+ ['column9 ' , 'boolean ' , []],
428+ ['column10 ' , 'datetime ' , []],
429+ ['column11 ' , 'binary ' , []],
430+ ['column12 ' , 'string ' , ['limit ' => 10 ]],
431+ ];
432+ }
433+
434+ /**
435+ * @dataProvider columnsProvider
436+ */
437+ public function testGetColumns ($ colName , $ type , $ options )
396438 {
397439 $ table = new \Phinx \Db \Table ('t ' , [], $ this ->adapter );
398- $ table ->addColumn ('column1 ' , 'string ' , ['null ' => true , 'default ' => null ])
399- ->addColumn ('column2 ' , 'integer ' , ['default ' => 0 ])
400- ->addColumn ('column3 ' , 'biginteger ' , ['default ' => 5 ])
401- ->addColumn ('column4 ' , 'text ' , ['default ' => 'text ' ])
402- ->addColumn ('column5 ' , 'float ' )
403- ->addColumn ('column6 ' , 'decimal ' )
404- ->addColumn ('column7 ' , 'time ' )
405- ->addColumn ('column8 ' , 'timestamp ' )
406- ->addColumn ('column9 ' , 'date ' )
407- ->addColumn ('column10 ' , 'boolean ' )
408- ->addColumn ('column11 ' , 'datetime ' )
409- ->addColumn ('column12 ' , 'binary ' )
410- ->addColumn ('column13 ' , 'string ' , ['limit ' => 10 ]);
411- $ pendingColumns = $ table ->getPendingColumns ();
412- $ table ->save ();
413- $ columns = $ this ->adapter ->getColumns ('t ' );
414- $ this ->assertCount (count ($ pendingColumns ) + 1 , $ columns );
415- for ($ i = 0 ; $ i ++; $ i < count ($ pendingColumns )) {
416- $ this ->assertEquals ($ pendingColumns [$ i ], $ columns [$ i + 1 ]);
417- }
440+ $ table
441+ ->addColumn ($ colName , $ type , $ options )
442+ ->save ();
418443
419- $ this ->assertNull ( $ columns [ ' column1 ' ]-> getDefault () );
420- $ this ->assertSame ( 0 , $ columns[ ' column2 ' ]-> getDefault () );
421- $ this ->assertSame ( 5 , $ columns [' column3 ' ]->getDefault ());
422- $ this ->assertSame ( ' text ' , $ columns [' column4 ' ]->getDefault ());
444+ $ columns = $ this ->adapter -> getColumns ( ' t ' );
445+ $ this ->assertCount ( 2 , $ columns );
446+ $ this ->assertEquals ( $ colName , $ columns [$ colName ]->getName ());
447+ $ this ->assertEquals ( $ type , $ columns [$ colName ]->getType ());
423448 }
424449
425450 public function testAddIndex ()
@@ -528,12 +553,12 @@ public function testAddForeignKey()
528553 $ table ->addColumn ('ref_table_id ' , 'integer ' )->save ();
529554
530555 $ fk = new \Phinx \Db \Table \ForeignKey ();
531- $ fk ->setReferencedTable ($ refTable )
556+ $ fk ->setReferencedTable ($ refTable-> getTable () )
532557 ->setColumns (['ref_table_id ' ])
533558 ->setReferencedColumns (['id ' ])
534559 ->setConstraint ('fk1 ' );
535560
536- $ this ->adapter ->addForeignKey ($ table , $ fk );
561+ $ this ->adapter ->addForeignKey ($ table-> getTable () , $ fk );
537562 $ this ->assertTrue ($ this ->adapter ->hasForeignKey ($ table ->getName (), ['ref_table_id ' ], 'fk1 ' ));
538563 }
539564
@@ -649,7 +674,7 @@ public function testRemoveColumnComment()
649674
650675 $ resultComment = $ this ->adapter ->getColumnComment ('table1 ' , 'field1 ' );
651676
652- $ this ->assertEmpty ($ resultComment , ' Dont remove column comment correctly' );
677+ $ this ->assertEmpty ($ resultComment , " Didn't remove column comment correctly: " . json_encode ( $ resultComment ) );
653678 }
654679
655680 /**
@@ -676,7 +701,8 @@ public function testBulkInsertData()
676701 $ table = new \Phinx \Db \Table ('table1 ' , [], $ this ->adapter );
677702 $ table ->addColumn ('column1 ' , 'string ' )
678703 ->addColumn ('column2 ' , 'integer ' )
679- ->insert ([
704+ ->save ();
705+ $ table ->insert ([
680706 [
681707 'column1 ' => 'value1 ' ,
682708 'column2 ' => 1 ,
@@ -692,8 +718,7 @@ public function testBulkInsertData()
692718 'column2 ' => 3 ,
693719 ]
694720 );
695- $ this ->adapter ->createTable ($ table );
696- $ this ->adapter ->bulkinsert ($ table , $ table ->getData ());
721+ $ this ->adapter ->bulkinsert ($ table ->getTable (), $ table ->getData ());
697722 $ table ->reset ();
698723
699724 $ rows = $ this ->adapter ->fetchAll ('SELECT * FROM table1 ' );
0 commit comments