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