Skip to content

Commit

Permalink
add Composer v1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Jun 17, 2021
1 parent b44fcd2 commit 00555b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: Tests
on: [push, pull_request]
jobs:
php:
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} Composer ${{ matrix.composer }}
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
composer: [v2]
php-versions:
- '5.3'
- '5.4'
Expand All @@ -23,11 +24,14 @@ jobs:
include:
- php-versions: '7.0'
composer-flags: '--prefer-lowest'
composer: v1
operating-system: ubuntu-latest
- php-versions: '5.3'
composer-flags: '--prefer-lowest'
composer: v1 # Global composer should be in same version as locally installed one
operating-system: ubuntu-latest
- php-versions: '8.0'
composer: v2
operating-system: windows-latest
steps:
- name: Checkout
Expand All @@ -38,6 +42,7 @@ jobs:
php-version: ${{ matrix.php-versions }}
extensions: json
coverage: xdebug
tools: composer:${{ matrix.composer }}
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
<env name="COMPOSER_ROOT_VERSION" value="1.x-dev"/>
</php>
<testsuites>
<testsuite name="Composer Diff Test Suite">
Expand Down
29 changes: 19 additions & 10 deletions tests/Integration/DiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use Composer\Composer;
use Composer\Console\Application;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Plugin\PluginManager;
use IonBazan\ComposerDiff\Command\DiffCommand;
use IonBazan\ComposerDiff\PackageDiff;
use IonBazan\ComposerDiff\Tests\TestCase;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -31,23 +34,24 @@ public function testCommand($expectedOutput, array $input)
* @param string $expectedOutput
*
* @dataProvider commandArgumentsDataProvider
*
* @runInSeparateProcess To handle autoloader stuff
*/
public function testComposerApplication($expectedOutput, array $input)
{
if (version_compare('2.0', Composer::VERSION, '>=')) {
$this->markTestSkipped('This test works properly only on Composer 2');
}

array_unshift($input, 'diff');
$input = array_merge(array('command' => 'diff'), $input);
$app = new ComposerApplication();
$app->setIO(new NullIO());
$app->setIO(new NullIO()); // For Composer v1
$app->setAutoExit(false);
$composer = $app->getComposer();
$composer->getPluginManager()->registerPackage($composer->getPackage(), true);
$composer = Factory::create($app->getIO(), null, true);
$app->setComposer($composer);
$pm = new PluginManager($app->getIO(), $composer);
$composer->setPluginManager($pm);
$pm->registerPackage($composer->getPackage(), true);
$tester = new ApplicationTester($app);
$result = $tester->run($input);
$this->assertSame(0, $result);
$result = $tester->run($input, array('verbosity' => Output::VERBOSITY_VERY_VERBOSE));
$this->assertSame($expectedOutput, $tester->getDisplay());
$this->assertSame(0, $result);
}

public function commandArgumentsDataProvider()
Expand Down Expand Up @@ -229,4 +233,9 @@ public function setIO(IOInterface $io)
{
$this->io = $io;
}

public function setComposer(Composer $composer)
{
$this->composer = $composer;
}
}

0 comments on commit 00555b9

Please sign in to comment.