Skip to content

Commit

Permalink
Do not print out status table when specifying --format json
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Sep 23, 2019
1 parent 70f1d15 commit c911501
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -13,7 +13,7 @@ environment:
- dependencies: highest
db: 2012
php_ddl: 56_nts
php_zip: php-5.6.28-nts-Win32-VC11-x86.zip
php_zip: php-5.6.40-nts-Win32-VC11-x86.zip
db_dsn: 'sqlserver://sa:Password12!@.\SQL2012SP1/phinxtesting?MultipleActiveResultSets=false'
sqlsrv: https://download.microsoft.com/download/C/D/B/CDB0A3BB-600E-42ED-8D5E-E4630C905371/SQLSRV32.EXE

Expand Down
10 changes: 8 additions & 2 deletions src/Phinx/Migration/Manager.php
Expand Up @@ -100,8 +100,8 @@ public function __construct(ConfigInterface $config, InputInterface $input, Outp
/**
* Prints the specified environment's migration status.
*
* @param string $environment
* @param null $format
* @param string $environment environment to print status of
* @param string|null $format format to print status in (either text, json, or null)
* @return int 0 if all migrations are up, or an error code
*/
public function printStatus($environment, $format = null)
Expand All @@ -114,6 +114,10 @@ public function printStatus($environment, $format = null)
$missingCount = 0;
$pendingMigrationCount = 0;
$finalMigrations = [];
$verbosity = $output->getVerbosity();
if ($format === 'json') {
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
if (count($migrations)) {
// TODO - rewrite using Symfony Table Helper as we already have this library
// included and it will fix formatting issues (e.g drawing the lines)
Expand Down Expand Up @@ -234,9 +238,11 @@ public function printStatus($environment, $format = null)

// write an empty line
$output->writeln('');

if ($format !== null) {
switch ($format) {
case 'json':
$output->setVerbosity($verbosity);
$output->writeln(json_encode(
[
'pending_count' => $pendingMigrationCount,
Expand Down
2 changes: 1 addition & 1 deletion tests/Phinx/Migration/ManagerTest.php
Expand Up @@ -198,7 +198,7 @@ public function testPrintStatusMethodJsonFormat()
$this->assertSame(0, $return);
rewind($this->manager->getOutput()->getStream());
$outputStr = trim(stream_get_contents($this->manager->getOutput()->getStream()));
$this->assertStringEndsWith('{"pending_count":0,"missing_count":0,"total_count":2,"migrations":[{"migration_status":"up","migration_id":"20120111235330","migration_name":"TestMigration"},{"migration_status":"up","migration_id":"20120116183504","migration_name":"TestMigration2"}]}', $outputStr);
$this->assertEquals('{"pending_count":0,"missing_count":0,"total_count":2,"migrations":[{"migration_status":"up","migration_id":"20120111235330","migration_name":"TestMigration"},{"migration_status":"up","migration_id":"20120116183504","migration_name":"TestMigration2"}]}', $outputStr);
}

public function testPrintStatusMethodWithNamespace()
Expand Down

0 comments on commit c911501

Please sign in to comment.