@@ -28,7 +28,7 @@ public function setUp()
2828 $ this ->initEnv ();
2929
3030 $ this ->createMigration ('0 ' , "CREATE TABLE test (id INTEGER, thevalue TEXT); " , "DROP TABLE test; " );
31- $ this ->createMigration ('1 ' , "INSERT INTO test VALUES (1, 'one'); " , "DELETE FROM test WHERE id = 1; " );
31+ $ this ->createMigration ('1 ' , "SELECT 1 " , "DELETE FROM test WHERE id = 1; " );
3232 $ this ->createMigration ('2 ' , "INSERT INTO test VALUES (2, 'two'); " , "DELETE FROM test WHERE id = 2; " );
3333
3434 self ::$ application = new Application ();
@@ -42,6 +42,50 @@ public function tearDown()
4242 $ this ->cleanEnv ();
4343 }
4444
45+ /**
46+ * @expectedException \RuntimeException
47+ */
48+ public function testUpMigrationWithError ()
49+ {
50+ $ this ->createMigration ('3 ' , "SELECT ; " , "SELECT ; " );
51+ $ command = self ::$ application ->find ('migrate:up ' );
52+ $ commandTester = new CommandTester ($ command );
53+
54+ $ commandTester ->execute (array (
55+ 'command ' => $ command ->getName (),
56+ 'env ' => 'testing '
57+ ));
58+ }
59+
60+ /**
61+ * @expectedException \RuntimeException
62+ */
63+ public function testDownMigrationWithError ()
64+ {
65+ $ this ->createMigration ('3 ' , "SELECT 1; " , "SELECT ; " );
66+
67+
68+ $ command = self ::$ application ->find ('migrate:up ' );
69+ $ commandTester = new CommandTester ($ command );
70+
71+ $ commandTester ->execute (array (
72+ 'command ' => $ command ->getName (),
73+ 'env ' => 'testing '
74+ ));
75+
76+ $ command = self ::$ application ->find ('migrate:down ' );
77+ $ commandTester = new CommandTester ($ command );
78+
79+ /* @var $question QuestionHelper */
80+ $ question = $ command ->getHelper ('question ' );
81+ $ question ->setInputStream (InputStreamUtil::type ("yes \n" ));
82+
83+ $ commandTester ->execute (array (
84+ 'command ' => $ command ->getName (),
85+ 'env ' => 'testing '
86+ ));
87+ }
88+
4589 public function testUpAllPendingMigrations ()
4690 {
4791
@@ -308,4 +352,56 @@ public function testDownTo()
308352
309353 $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
310354 }
355+
356+ /**
357+ * @expectedException \RuntimeException
358+ * @expectedExceptionMessage you are not in an initialized php-database-migration directory
359+ */
360+ public function testUpInANotInitializedDirectory ()
361+ {
362+ $ this ->cleanEnv ();
363+
364+ $ command = self ::$ application ->find ('migrate:up ' );
365+ $ commandTester = new CommandTester ($ command );
366+
367+ $ commandTester ->execute (array (
368+ 'command ' => $ command ->getName (),
369+ 'env ' => 'testing ' ,
370+ ));
371+
372+ $ command = self ::$ application ->find ('migrate:down ' );
373+ $ commandTester = new CommandTester ($ command );
374+
375+ $ commandTester ->execute (array (
376+ 'command ' => $ command ->getName (),
377+ 'env ' => 'testing ' ,
378+ '--to ' => '1 '
379+ ));
380+ }
381+
382+ /**
383+ * @expectedException \RuntimeException
384+ * @expectedExceptionMessage you are not in an initialized php-database-migration directory
385+ */
386+ public function testDownInANotInitializedDirectory ()
387+ {
388+ $ this ->cleanEnv ();
389+
390+ $ command = self ::$ application ->find ('migrate:down ' );
391+ $ commandTester = new CommandTester ($ command );
392+
393+ $ commandTester ->execute (array (
394+ 'command ' => $ command ->getName (),
395+ 'env ' => 'testing ' ,
396+ ));
397+
398+ $ command = self ::$ application ->find ('migrate:down ' );
399+ $ commandTester = new CommandTester ($ command );
400+
401+ $ commandTester ->execute (array (
402+ 'command ' => $ command ->getName (),
403+ 'env ' => 'testing ' ,
404+ '--to ' => '1 '
405+ ));
406+ }
311407}
0 commit comments