The phinx status works well with text format -f text but prints both formats when selecting JSON format -f json.
Here the output (notice the last line):
#> php vendor/bin/phinx -f json
Phinx by Rob Morgan - https://phinx.org. version 0.6.4
using config file ./phinx.yml
using config parser yaml
using migration path /foo/bar/data/migrations
using seed path /foo/bar/data/seeds
using environment development
using format json
Status Migration ID Started Finished Migration Name
----------------------------------------------------------------------------------
up 20160829130325 2016-09-01 19:04:54 2016-09-01 19:04:55 xxx
up 20160830123204 2016-09-01 19:06:02 2016-09-01 19:06:02 xxx
up 20160830164920 2016-09-01 19:06:02 2016-09-01 19:06:02 xxx
up 20160831142539 2016-09-01 19:06:02 2016-09-01 19:06:02 xxx
up 20160901165958 2016-09-01 19:06:58 2016-09-01 19:06:58 xxx
up 20160907155023 2016-09-07 17:52:35 2016-09-07 17:52:35 xxx
up 20160907162327 2016-09-07 18:29:17 2016-09-07 18:29:17 xxx
up 20160908151045 2016-09-13 17:40:52 2016-09-13 17:40:52 xxx
up 20160908152839 2016-09-08 17:30:53 2016-09-08 17:30:53 xxx
up 20160908154600 2016-09-08 17:49:26 2016-09-08 17:49:26 xxx
up 20160908160020 2016-09-08 18:21:07 2016-09-08 18:21:07 xxx
up 20160913085001 2016-09-27 17:29:23 2016-09-27 17:29:23 xxx
up 20160913153834 2016-09-13 17:41:12 2016-09-13 17:41:12 xxx
up 20160916142746 2016-09-27 17:29:23 2016-09-27 17:29:23 xxx
up 20160916163002 2016-09-27 17:29:23 2016-09-27 17:29:23 xxx
up 20160919175002 2016-09-27 17:29:23 2016-09-27 17:29:23 xxx
up 20160922165747 2016-09-28 18:13:05 2016-09-28 18:13:05 xxx
up 20160926134227 2016-09-27 17:29:23 2016-09-27 17:29:23 xxx
up 20160926151932 2016-09-28 18:13:05 2016-09-28 18:13:05 xxx
down 20160928170557 xxx
down 20160928182625 xxx
{"pending_count":21,"migrations":[{"migration_status":"up","migration_id":"20160829130325","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160830123204","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160830164920","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160831142539","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160901165958","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160907155023","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160907162327","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160908151045","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160908152839","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160908154600","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160908160020","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160913085001","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160913153834","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160916142746","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160916163002","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160919175002","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160922165747","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160926134227","migration_name":"xxx"},{"migration_status":"up","migration_id":"20160926151932","migration_name":"xxx"},{"migration_status":"down","migration_id":"20160928170557","migration_name":"xxx"},{"migration_status":"down","migration_id":"20160928182625","migration_name":"xxx"}]}
I don't know if it works as expected, but it seems weird and very hard to parse.
I advice to add the condition (null === $format || 'text' == $format) here https://github.com/robmorgan/phinx/blob/0.6.x-dev/src/Phinx/Migration/Manager.php#L108
From what I can tell, this is fully intentional. It is expected that anyone parsing this output will use tail -n1 to capture the last line of output and then parse that.
If it's intentional, it should be mentioned in the option description and provide your advise (tail -n1) as possibility of getting the JSON part.
But, anyone who want to parse the response should not parse the output to retrieve the right formatted content...
My two cents: This behavior is contrary to 99.9% of all the tools out there. If the user specifies the format json, he expects valid json and only json.
Was there ever a conclusion as to what the proper behavior is? I agree with @bonndan in that printing both text and json when specifying --format=json is really weird and caught me for surprise and I ended up spending some time googling about it since I thought I must have been doing something wrong and there's nothing in the documentation about it.
I also agree that the opened PR fixes this in a way that is expected behavior. So I will close this now as the PR resolves the issue.
Most helpful comment
My two cents: This behavior is contrary to 99.9% of all the tools out there. If the user specifies the format json, he expects valid json and only json.