@@ -67,7 +67,8 @@ public function testDump($format, $withFormatOption = true)
6767 $ this ->assertCommandExecution (
6868 $ input ,
6969 __DIR__ .'/fixtures/schema. ' .$ format ,
70- $ file
70+ $ file ,
71+ $ format
7172 );
7273 }
7374
@@ -82,7 +83,8 @@ public function testClassicJsonFormat()
8283 '--format ' => 'json ' ,
8384 ],
8485 __DIR__ .'/fixtures/schema.json ' ,
85- $ file
86+ $ file ,
87+ 'json '
8688 );
8789 }
8890
@@ -97,7 +99,8 @@ public function testModernJsonFormat()
9799 '--format ' => 'json ' ,
98100 ],
99101 __DIR__ .'/fixtures/schema.modern.json ' ,
100- $ file
102+ $ file ,
103+ 'json '
101104 );
102105 }
103106
@@ -136,11 +139,33 @@ public function formatDataProvider()
136139 ];
137140 }
138141
139- private function assertCommandExecution (array $ input , $ expectedFile , $ actualFile , $ expectedStatusCode = 0 )
142+ private function assertCommandExecution (array $ input , $ expectedFile , $ actualFile , $ format , $ expectedStatusCode = 0 )
140143 {
141144 $ this ->commandTester ->execute ($ input );
142145
143146 $ this ->assertEquals ($ expectedStatusCode , $ this ->commandTester ->getStatusCode ());
144- $ this ->assertEquals (trim (file_get_contents ($ expectedFile )), trim (file_get_contents ($ actualFile )));
147+ $ expected = trim (file_get_contents ($ expectedFile ));
148+ $ actual = trim (file_get_contents ($ actualFile ));
149+ if ('json ' === $ format ) {
150+ $ expected = json_decode ($ expected , true );
151+ $ actual = json_decode ($ actual , true );
152+ $ this ->sortSchemaEntry ($ expected , 'types ' , 'name ' );
153+ $ this ->sortSchemaEntry ($ actual , 'types ' , 'name ' );
154+ }
155+
156+ $ this ->assertEquals ($ expected , $ actual );
157+ }
158+
159+ private function sortSchemaEntry (array &$ entries , $ entryKey , $ sortBy )
160+ {
161+ if (isset ($ entries ['data ' ]['__schema ' ][$ entryKey ])) {
162+ $ data = &$ entries ['data ' ]['__schema ' ][$ entryKey ];
163+ } else {
164+ $ data = &$ entries ['__schema ' ][$ entryKey ];
165+ }
166+
167+ usort ($ data , function ($ data1 , $ data2 ) use ($ sortBy ) {
168+ return strcmp ($ data1 [$ sortBy ], $ data2 [$ sortBy ]);
169+ });
145170 }
146171}
0 commit comments