1919
2020class UpDownCommandTest extends AbstractCommandTester
2121{
22+ public static $ application ;
23+
2224 public function setUp ()
2325 {
2426 $ this ->cleanEnv ();
2527 $ this ->createEnv ();
2628 $ this ->initEnv ();
29+
30+ $ 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; " );
32+ $ this ->createMigration ('2 ' , "INSERT INTO test VALUES (2, 'two'); " , "DELETE FROM test WHERE id = 2; " );
33+
34+ self ::$ application = new Application ();
35+ self ::$ application ->add (new UpCommand ());
36+ self ::$ application ->add (new DownCommand ());
37+ self ::$ application ->add (new StatusCommand ());
2738 }
2839
2940 public function tearDown ()
@@ -33,14 +44,8 @@ public function tearDown()
3344
3445 public function testUpAllPendingMigrations ()
3546 {
36- $ this ->createMigration ('0 ' , "CREATE TABLE test (id INTEGER, thevalue TEXT); " , "DROP TABLE test; " );
37- $ this ->createMigration ('1 ' , "INSERT INTO test VALUES (1, 'one'); " , "DROP TABLE test; " );
38- $ this ->createMigration ('2 ' , "INSERT INTO test VALUES (2, 'two'); " , "DROP TABLE test; " );
3947
40- $ application = new Application ();
41- $ application ->add (new UpCommand ());
42-
43- $ command = $ application ->find ('migrate:up ' );
48+ $ command = self ::$ application ->find ('migrate:up ' );
4449 $ commandTester = new CommandTester ($ command );
4550
4651 $ commandTester ->execute (array (
@@ -57,20 +62,12 @@ public function testUpAllPendingMigrations()
5762
5863EXPECTED ;
5964
60- $ this ->assertEquals ($ commandTester ->getDisplay (), $ expected );
65+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
6166 }
6267
6368 public function testDownLastMigration ()
6469 {
65- $ this ->createMigration ('0 ' , "CREATE TABLE test (id INTEGER, thevalue TEXT); " , "DROP TABLE test; " );
66- $ this ->createMigration ('1 ' , "INSERT INTO test VALUES (1, 'one'); " , "DROP TABLE test; " );
67- $ this ->createMigration ('2 ' , "INSERT INTO test VALUES (2, 'two'); " , "DROP TABLE test; " );
68-
69- $ application = new Application ();
70- $ application ->add (new UpCommand ());
71- $ application ->add (new DownCommand ());
72-
73- $ command = $ application ->find ('migrate:up ' );
70+ $ command = self ::$ application ->find ('migrate:up ' );
7471 $ commandTester = new CommandTester ($ command );
7572
7673 $ commandTester ->execute (array (
@@ -80,7 +77,7 @@ public function testDownLastMigration()
8077
8178
8279
83- $ command = $ application ->find ('migrate:down ' );
80+ $ command = self :: $ application ->find ('migrate:down ' );
8481 $ commandTester = new CommandTester ($ command );
8582
8683 /* @var $question QuestionHelper */
@@ -104,17 +101,67 @@ public function testDownLastMigration()
104101
105102 public function testUpOnly ()
106103 {
107- $ this ->createMigration ('0 ' , "CREATE TABLE test (id INTEGER, thevalue TEXT); " , "DROP TABLE test; " );
108- $ this ->createMigration ('1 ' , "INSERT INTO test VALUES (1, 'one'); " , "DROP TABLE test; " );
109- $ this ->createMigration ('2 ' , "INSERT INTO test VALUES (2, 'two'); " , "DROP TABLE test; " );
104+ $ command = self ::$ application ->find ('migrate:up ' );
105+ $ commandTester = new CommandTester ($ command );
110106
111- $ application = new Application ();
112- $ application ->add (new UpCommand ());
113- $ application ->add (new StatusCommand ());
107+ $ commandTester ->execute (array (
108+ 'command ' => $ command ->getName (),
109+ 'env ' => 'testing ' ,
110+ '--only ' => '1 '
111+ ));
114112
115- $ command = $ application ->find ('migrate:up ' );
113+ $ expected =<<<EXPECTED
114+ connected
115+ 0/1 [>---------------------------] 0 % []
116+ 1/1 [============================] 100 % [migration]
117+
118+ EXPECTED ;
119+
120+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
121+
122+ $ command = self ::$ application ->find ('migrate:status ' );
116123 $ commandTester = new CommandTester ($ command );
117124
125+ $ currentDate = date ('Y-m-d H:i:s ' );
126+
127+ $ commandTester ->execute (array (
128+ 'command ' => $ command ->getName (),
129+ 'env ' => 'testing '
130+ ));
131+
132+
133+ $ expected =<<<EXPECTED
134+ connected
135+ +----+---------+---------------------+-------------+
136+ | id | version | applied at | description |
137+ +----+---------+---------------------+-------------+
138+ | 0 | | | migration |
139+ | 1 | | $ currentDate | migration |
140+ | 2 | | | migration |
141+ +----+---------+---------------------+-------------+
142+
143+ EXPECTED ;
144+
145+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
146+ }
147+
148+ public function testDownOnly ()
149+ {
150+ $ command = self ::$ application ->find ('migrate:up ' );
151+ $ commandTester = new CommandTester ($ command );
152+
153+ $ commandTester ->execute (array (
154+ 'command ' => $ command ->getName (),
155+ 'env ' => 'testing '
156+ ));
157+
158+ $ command = self ::$ application ->find ('migrate:down ' );
159+ $ commandTester = new CommandTester ($ command );
160+
161+ /* @var $question QuestionHelper */
162+ $ question = $ command ->getHelper ('question ' );
163+ $ question ->setInputStream (InputStreamUtil::type ("yes \n" ));
164+
118165 $ commandTester ->execute (array (
119166 'command ' => $ command ->getName (),
120167 'env ' => 'testing ' ,
@@ -123,33 +170,140 @@ public function testUpOnly()
123170
124171 $ expected =<<<EXPECTED
125172connected
126- 0/1 [>---------------------------] 0 % []
173+ Are you sure? (yes/no) [no]: 0/1 [>---------------------------] 0 % []
1271741/1 [============================] 100 % [migration]
128175
129176EXPECTED ;
130177
131178 $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
132179
133- $ command = $ application ->find ('migrate:status ' );
180+ $ command = self :: $ application ->find ('migrate:status ' );
134181 $ commandTester = new CommandTester ($ command );
135182
183+ $ currentDate = date ('Y-m-d H:i:s ' );
184+
136185 $ commandTester ->execute (array (
137186 'command ' => $ command ->getName (),
138187 'env ' => 'testing '
139188 ));
140189
190+ $ expected =<<<EXPECTED
191+ connected
192+ +----+---------+---------------------+-------------+
193+ | id | version | applied at | description |
194+ +----+---------+---------------------+-------------+
195+ | 0 | | $ currentDate | migration |
196+ | 1 | | | migration |
197+ | 2 | | $ currentDate | migration |
198+ +----+---------+---------------------+-------------+
199+
200+ EXPECTED ;
201+
202+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
203+
204+ }
205+
206+ public function testUpTo ()
207+ {
208+ $ command = self ::$ application ->find ('migrate:up ' );
209+ $ commandTester = new CommandTester ($ command );
210+
211+ $ commandTester ->execute (array (
212+ 'command ' => $ command ->getName (),
213+ 'env ' => 'testing ' ,
214+ '--to ' => '1 '
215+ ));
216+
217+ $ expected =<<<EXPECTED
218+ connected
219+ 0/2 [>---------------------------] 0 % []
220+ 1/2 [==============>-------------] 50 % [migration]
221+ 2/2 [============================] 100 % [migration]
222+
223+ EXPECTED ;
224+
225+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
226+
227+ $ command = self ::$ application ->find ('migrate:status ' );
228+ $ commandTester = new CommandTester ($ command );
229+
141230 $ currentDate = date ('Y-m-d H:i:s ' );
142231
232+ $ commandTester ->execute (array (
233+ 'command ' => $ command ->getName (),
234+ 'env ' => 'testing '
235+ ));
236+
237+
143238 $ expected =<<<EXPECTED
144239connected
145240+----+---------+---------------------+-------------+
146241| id | version | applied at | description |
147242+----+---------+---------------------+-------------+
148- | 0 | | | migration |
243+ | 0 | | $ currentDate | migration |
149244| 1 | | $ currentDate | migration |
150245| 2 | | | migration |
151246+----+---------+---------------------+-------------+
152247
248+ EXPECTED ;
249+
250+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
251+ }
252+
253+ public function testDownTo ()
254+ {
255+ $ command = self ::$ application ->find ('migrate:up ' );
256+ $ commandTester = new CommandTester ($ command );
257+
258+ $ commandTester ->execute (array (
259+ 'command ' => $ command ->getName (),
260+ 'env ' => 'testing ' ,
261+ ));
262+
263+ $ command = self ::$ application ->find ('migrate:down ' );
264+ $ commandTester = new CommandTester ($ command );
265+
266+ /* @var $question QuestionHelper */
267+ $ question = $ command ->getHelper ('question ' );
268+ $ question ->setInputStream (InputStreamUtil::type ("yes \n" ));
269+
270+ $ commandTester ->execute (array (
271+ 'command ' => $ command ->getName (),
272+ 'env ' => 'testing ' ,
273+ '--to ' => '1 '
274+ ));
275+
276+ $ expected =<<<EXPECTED
277+ connected
278+ Are you sure? (yes/no) [no]: 0/2 [>---------------------------] 0 % []
279+ 1/2 [==============>-------------] 50 % [migration]
280+ 2/2 [============================] 100 % [migration]
281+
282+ EXPECTED ;
283+
284+ $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
285+
286+ $ command = self ::$ application ->find ('migrate:status ' );
287+ $ commandTester = new CommandTester ($ command );
288+
289+ $ currentDate = date ('Y-m-d H:i:s ' );
290+
291+ $ commandTester ->execute (array (
292+ 'command ' => $ command ->getName (),
293+ 'env ' => 'testing '
294+ ));
295+
296+
297+ $ expected =<<<EXPECTED
298+ connected
299+ +----+---------+---------------------+-------------+
300+ | id | version | applied at | description |
301+ +----+---------+---------------------+-------------+
302+ | 0 | | $ currentDate | migration |
303+ | 1 | | | migration |
304+ | 2 | | | migration |
305+ +----+---------+---------------------+-------------+
306+
153307EXPECTED ;
154308
155309 $ this ->assertEquals ($ expected , $ commandTester ->getDisplay ());
0 commit comments