22
33namespace IonBazan \ComposerDiff \Tests \Integration ;
44
5+ use Composer \Composer ;
6+ use Composer \Console \Application ;
7+ use Composer \IO \IOInterface ;
8+ use Composer \IO \NullIO ;
59use IonBazan \ComposerDiff \Command \DiffCommand ;
610use IonBazan \ComposerDiff \PackageDiff ;
711use IonBazan \ComposerDiff \Tests \TestCase ;
12+ use Symfony \Component \Console \Tester \ApplicationTester ;
813use Symfony \Component \Console \Tester \CommandTester ;
914
1015class DiffCommandTest extends TestCase
@@ -22,6 +27,29 @@ public function testCommand($expectedOutput, array $input)
2227 $ this ->assertSame ($ expectedOutput , $ tester ->getDisplay ());
2328 }
2429
30+ /**
31+ * @param string $expectedOutput
32+ *
33+ * @dataProvider commandArgumentsDataProvider
34+ */
35+ public function testComposerApplication ($ expectedOutput , array $ input )
36+ {
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+ $ app = new ComposerApplication ();
43+ $ app ->setIO (new NullIO ());
44+ $ app ->setAutoExit (false );
45+ $ composer = $ app ->getComposer ();
46+ $ composer ->getPluginManager ()->registerPackage ($ composer ->getPackage (), true );
47+ $ tester = new ApplicationTester ($ app );
48+ $ result = $ tester ->run ($ input );
49+ $ this ->assertSame (0 , $ result );
50+ $ this ->assertSame ($ expectedOutput , $ tester ->getDisplay ());
51+ }
52+
2553 public function commandArgumentsDataProvider ()
2654 {
2755 return array (
@@ -194,3 +222,11 @@ public function commandArgumentsDataProvider()
194222 );
195223 }
196224}
225+
226+ class ComposerApplication extends Application
227+ {
228+ public function setIO (IOInterface $ io )
229+ {
230+ $ this ->io = $ io ;
231+ }
232+ }
0 commit comments