44
55use Composer \Composer ;
66use Composer \Console \Application ;
7+ use Composer \Factory ;
78use Composer \IO \IOInterface ;
89use Composer \IO \NullIO ;
10+ use Composer \Plugin \PluginManager ;
911use IonBazan \ComposerDiff \Command \DiffCommand ;
1012use IonBazan \ComposerDiff \PackageDiff ;
1113use IonBazan \ComposerDiff \Tests \TestCase ;
14+ use Symfony \Component \Console \Output \Output ;
1215use Symfony \Component \Console \Tester \ApplicationTester ;
1316use Symfony \Component \Console \Tester \CommandTester ;
1417
@@ -31,23 +34,24 @@ public function testCommand($expectedOutput, array $input)
3134 * @param string $expectedOutput
3235 *
3336 * @dataProvider commandArgumentsDataProvider
37+ *
38+ * @runInSeparateProcess To handle autoloader stuff
3439 */
3540 public function testComposerApplication ($ expectedOutput , array $ input )
3641 {
37- if (version_compare ('2.0 ' , Composer::VERSION , '>= ' )) {
38- $ this ->markTestSkipped ('This test works properly only on Composer 2 ' );
39- }
40-
41- array_unshift ($ input , 'diff ' );
42+ $ input = array_merge (array ('command ' => 'diff ' ), $ input );
4243 $ app = new ComposerApplication ();
43- $ app ->setIO (new NullIO ());
44+ $ app ->setIO (new NullIO ()); // For Composer v1
4445 $ app ->setAutoExit (false );
45- $ composer = $ app ->getComposer ();
46- $ composer ->getPluginManager ()->registerPackage ($ composer ->getPackage (), true );
46+ $ composer = Factory::create ($ app ->getIO (), null , true );
47+ $ app ->setComposer ($ composer );
48+ $ pm = new PluginManager ($ app ->getIO (), $ composer );
49+ $ composer ->setPluginManager ($ pm );
50+ $ pm ->registerPackage ($ composer ->getPackage (), true );
4751 $ tester = new ApplicationTester ($ app );
48- $ result = $ tester ->run ($ input );
49- $ this ->assertSame (0 , $ result );
52+ $ result = $ tester ->run ($ input , array ('verbosity ' => Output::VERBOSITY_VERY_VERBOSE ));
5053 $ this ->assertSame ($ expectedOutput , $ tester ->getDisplay ());
54+ $ this ->assertSame (0 , $ result );
5155 }
5256
5357 public function commandArgumentsDataProvider ()
@@ -229,4 +233,9 @@ public function setIO(IOInterface $io)
229233 {
230234 $ this ->io = $ io ;
231235 }
236+
237+ public function setComposer (Composer $ composer )
238+ {
239+ $ this ->composer = $ composer ;
240+ }
232241}
0 commit comments