Skip to content

Commit a968372

Browse files
authored
Merge pull request #8 from IonBazan/plugin-test
add Composer v1 tests
2 parents 6c50a71 + 00555b9 commit a968372

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ name: Tests
22
on: [push, pull_request]
33
jobs:
44
php:
5-
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}
5+
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} Composer ${{ matrix.composer }}
66
runs-on: ${{ matrix.operating-system }}
77
strategy:
88
fail-fast: false
99
matrix:
1010
operating-system: [ubuntu-latest]
11+
composer: [v2]
1112
php-versions:
1213
- '5.3'
1314
- '5.4'
@@ -23,11 +24,14 @@ jobs:
2324
include:
2425
- php-versions: '7.0'
2526
composer-flags: '--prefer-lowest'
27+
composer: v1
2628
operating-system: ubuntu-latest
2729
- php-versions: '5.3'
2830
composer-flags: '--prefer-lowest'
31+
composer: v1 # Global composer should be in same version as locally installed one
2932
operating-system: ubuntu-latest
3033
- php-versions: '8.0'
34+
composer: v2
3135
operating-system: windows-latest
3236
steps:
3337
- name: Checkout
@@ -38,6 +42,7 @@ jobs:
3842
php-version: ${{ matrix.php-versions }}
3943
extensions: json
4044
coverage: xdebug
45+
tools: composer:${{ matrix.composer }}
4146
- name: Get composer cache directory
4247
id: composer-cache
4348
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<php>
1818
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
1919
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
20+
<env name="COMPOSER_ROOT_VERSION" value="1.x-dev"/>
2021
</php>
2122
<testsuites>
2223
<testsuite name="Composer Diff Test Suite">

tests/Integration/DiffCommandTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use Composer\Composer;
66
use Composer\Console\Application;
7+
use Composer\Factory;
78
use Composer\IO\IOInterface;
89
use Composer\IO\NullIO;
10+
use Composer\Plugin\PluginManager;
911
use IonBazan\ComposerDiff\Command\DiffCommand;
1012
use IonBazan\ComposerDiff\PackageDiff;
1113
use IonBazan\ComposerDiff\Tests\TestCase;
14+
use Symfony\Component\Console\Output\Output;
1215
use Symfony\Component\Console\Tester\ApplicationTester;
1316
use 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

Comments
 (0)