@@ -19,6 +19,7 @@ class StatusCommandTest extends AntiMattrTestCase
1919 private $ config ;
2020 private $ migration ;
2121 private $ version ;
22+ private $ version2 ;
2223
2324 protected function setUp ()
2425 {
@@ -27,6 +28,7 @@ protected function setUp()
2728 $ this ->config = $ this ->buildMock ('AntiMattr\MongoDB\Migrations\Configuration\Configuration ' );
2829 $ this ->migration = $ this ->buildMock ('AntiMattr\MongoDB\Migrations\Migration ' );
2930 $ this ->version = $ this ->buildMock ('AntiMattr\MongoDB\Migrations\Version ' );
31+ $ this ->version2 = $ this ->buildMock ('AntiMattr\MongoDB\Migrations\Version ' );
3032
3133 $ this ->command ->setMigrationConfiguration ($ this ->config );
3234 }
@@ -212,6 +214,254 @@ public function testExecuteWithoutShowingVersions()
212214 $ this ->output
213215 );
214216 }
217+
218+ public function testExecuteWithShowingVersions ()
219+ {
220+ $ input = new ArgvInput (
221+ array (
222+ StatusCommand::NAME ,
223+ '--show-versions ' ,
224+ )
225+ );
226+
227+ $ configName = 'config-name ' ;
228+ $ databaseDriver = 'MongoDB ' ;
229+ $ migrationsDatabaseName = ' migrations-database-name ' ;
230+ $ migrationsCollectionName = 'migrations-collection-name ' ;
231+ $ migrationsNamespace = 'migrations-namespace ' ;
232+ $ migrationsDirectory = 'migrations-directory ' ;
233+ $ currentVersion = 'abcdefghijk ' ;
234+ $ latestVersion = '1234567890 ' ;
235+ $ numExecutedMigrations = 2 ;
236+ $ numExecutedUnavailableMigrations = 1 ;
237+ $ numAvailableMigrations = 2 ;
238+ $ numNewMigrations = 1 ;
239+ $ notMigratedVersion = '20140822185743 ' ;
240+ $ migratedVersion = '20140822185745 ' ;
241+ $ unavailableMigratedVersion = '20140822185744 ' ;
242+
243+ // Expectations
244+ $ this ->version ->expects ($ this ->exactly (3 ))
245+ ->method ('getVersion ' )
246+ ->will ($ this ->returnValue ($ notMigratedVersion ));
247+
248+ $ this ->version2 ->expects ($ this ->exactly (3 ))
249+ ->method ('getVersion ' )
250+ ->will ($ this ->returnValue ($ migratedVersion ));
251+
252+ $ this ->config ->expects ($ this ->once ())
253+ ->method ('getDetailsMap ' )
254+ ->will (
255+ $ this ->returnValue (
256+ array (
257+ 'name ' => $ configName ,
258+ 'database_driver ' => $ databaseDriver ,
259+ 'migrations_database_name ' => $ migrationsDatabaseName ,
260+ 'migrations_collection_name ' => $ migrationsCollectionName ,
261+ 'migrations_namespace ' => $ migrationsNamespace ,
262+ 'migrations_directory ' => $ migrationsDirectory ,
263+ 'current_version ' => $ currentVersion ,
264+ 'latest_version ' => $ latestVersion ,
265+ 'num_executed_migrations ' => $ numExecutedMigrations ,
266+ 'num_executed_unavailable_migrations ' => $ numExecutedUnavailableMigrations ,
267+ 'num_available_migrations ' => $ numAvailableMigrations ,
268+ 'num_new_migrations ' => $ numNewMigrations ,
269+ )
270+ )
271+ )
272+ ;
273+ $ this ->config ->expects ($ this ->once ())
274+ ->method ('getMigrations ' )
275+ ->will (
276+ $ this ->returnValue (
277+ array ($ this ->version , $ this ->version2 )
278+ )
279+ )
280+ ;
281+ $ this ->config ->expects ($ this ->once ())
282+ ->method ('getMigratedVersions ' )
283+ ->will (
284+ $ this ->returnValue (
285+ array ($ unavailableMigratedVersion , $ migratedVersion )
286+ )
287+ )
288+ ;
289+ $ this ->config ->expects ($ this ->once ())
290+ ->method ('getUnavailableMigratedVersions ' )
291+ ->will (
292+ $ this ->returnValue (
293+ array ($ unavailableMigratedVersion )
294+ )
295+ )
296+ ;
297+
298+ $ this ->output ->expects ($ this ->at (0 ))
299+ ->method ('writeln ' )
300+ ->with (
301+ "\n <info>==</info> Configuration \n"
302+ )
303+ ;
304+ $ this ->output ->expects ($ this ->at (1 ))
305+ ->method ('writeln ' )
306+ ->with (
307+ sprintf (
308+ '%s::%s ' ,
309+ 'Name ' ,
310+ $ configName
311+ )
312+ )
313+ ;
314+ $ this ->output ->expects ($ this ->at (2 ))
315+ ->method ('writeln ' )
316+ ->with (
317+ sprintf (
318+ '%s::%s ' ,
319+ 'Database Driver ' ,
320+ 'MongoDB '
321+ )
322+ )
323+ ;
324+ $ this ->output ->expects ($ this ->at (3 ))
325+ ->method ('writeln ' )
326+ ->with (
327+ sprintf (
328+ '%s::%s ' ,
329+ 'Database Name ' ,
330+ $ migrationsDatabaseName
331+ )
332+ )
333+ ;
334+ $ this ->output ->expects ($ this ->at (4 ))
335+ ->method ('writeln ' )
336+ ->with (
337+ sprintf (
338+ '%s::%s ' ,
339+ 'Configuration Source ' ,
340+ 'manually configured '
341+ )
342+ )
343+ ;
344+ $ this ->output ->expects ($ this ->at (5 ))
345+ ->method ('writeln ' )
346+ ->with (
347+ sprintf (
348+ '%s::%s ' ,
349+ 'Version Collection Name ' ,
350+ $ migrationsCollectionName
351+ )
352+ )
353+ ;
354+ $ this ->output ->expects ($ this ->at (6 ))
355+ ->method ('writeln ' )
356+ ->with (
357+ sprintf (
358+ '%s::%s ' ,
359+ 'Migrations Namespace ' ,
360+ $ migrationsNamespace
361+ )
362+ )
363+ ;
364+ $ this ->output ->expects ($ this ->at (7 ))
365+ ->method ('writeln ' )
366+ ->with (
367+ sprintf (
368+ '%s::%s ' ,
369+ 'Migrations Directory ' ,
370+ $ migrationsDirectory
371+ )
372+ )
373+ ;
374+ $ this ->output ->expects ($ this ->at (8 )) // current version formatted
375+ ->method ('writeln ' )
376+ ;
377+ $ this ->output ->expects ($ this ->at (9 )) // latest version formatted
378+ ->method ('writeln ' )
379+ ;
380+ $ this ->output ->expects ($ this ->at (10 ))
381+ ->method ('writeln ' )
382+ ->with (
383+ sprintf (
384+ '%s::%s ' ,
385+ 'Executed Migrations ' ,
386+ $ numExecutedMigrations
387+ )
388+ )
389+ ;
390+ $ this ->output ->expects ($ this ->at (11 ))
391+ ->method ('writeln ' )
392+ ->with (
393+ sprintf (
394+ '%s::<error>%s</error> ' ,
395+ 'Executed Unavailable Migrations ' ,
396+ $ numExecutedUnavailableMigrations
397+ )
398+ )
399+ ;
400+ $ this ->output ->expects ($ this ->at (12 ))
401+ ->method ('writeln ' )
402+ ->with (
403+ sprintf (
404+ '%s::%s ' ,
405+ 'Available Migrations ' ,
406+ $ numAvailableMigrations
407+ )
408+ )
409+ ;
410+ $ this ->output ->expects ($ this ->at (13 ))
411+ ->method ('writeln ' )
412+ ->with (
413+ sprintf (
414+ '%s::<question>%s</question> ' ,
415+ 'New Migrations ' ,
416+ $ numNewMigrations
417+ )
418+ )
419+ ;
420+ $ this ->output ->expects ($ this ->at (14 ))
421+ ->method ('writeln ' )
422+ ->with ("\n <info>==</info> Available Migration Versions \n" )
423+ ;
424+ $ this ->output ->expects ($ this ->at (15 ))
425+ ->method ('writeln ' )
426+ ->with (
427+ sprintf (
428+ ' <comment>>></comment> %s (<comment>%s</comment>) <error>not migrated</error> ' ,
429+ \DateTime::createFromFormat ('YmdHis ' , $ notMigratedVersion )->format ('Y-m-d H:i:s ' ),
430+ $ notMigratedVersion
431+ )
432+ )
433+ ;
434+ $ this ->output ->expects ($ this ->at (16 ))
435+ ->method ('writeln ' )
436+ ->with (
437+ sprintf (
438+ ' <comment>>></comment> %s (<comment>%s</comment>) <info>migrated</info> ' ,
439+ \DateTime::createFromFormat ('YmdHis ' , $ migratedVersion )->format ('Y-m-d H:i:s ' ),
440+ $ migratedVersion
441+ )
442+ )
443+ ;
444+ $ this ->output ->expects ($ this ->at (17 ))
445+ ->method ('writeln ' )
446+ ->with ("\n <info>==</info> Previously Executed Unavailable Migration Versions \n" )
447+ ;
448+ $ this ->output ->expects ($ this ->at (18 ))
449+ ->method ('writeln ' )
450+ ->with (
451+ sprintf (
452+ ' <comment>>></comment> %s (<comment>%s</comment>) ' ,
453+ \DateTime::createFromFormat ('YmdHis ' , $ unavailableMigratedVersion )->format ('Y-m-d H:i:s ' ),
454+ $ unavailableMigratedVersion
455+ )
456+ )
457+ ;
458+
459+ // Run command, run.
460+ $ this ->command ->run (
461+ $ input ,
462+ $ this ->output
463+ );
464+ }
215465}
216466
217467class StatusCommandStub extends StatusCommand
0 commit comments