From 43150b88a29a3dd85f0900f0924c286645ab8f90 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 28 May 2012 00:11:18 +0200 Subject: [PATCH] Refactor integration tests to accept any run command --- tests/Composer/Test/Fixtures/installer/SAMPLE | 4 +- .../aliased-priority-conflicting.test | 2 + .../Fixtures/installer/aliased-priority.test | 2 + .../Test/Fixtures/installer/install-dev.test | 4 +- .../Fixtures/installer/install-reference.test | 2 + .../Fixtures/installer/install-simple.test | 2 + .../Test/Fixtures/installer/update-all.test | 4 +- .../Fixtures/installer/update-reference.test | 2 + tests/Composer/Test/InstallerTest.php | 42 ++++++++++++++----- 9 files changed, 50 insertions(+), 14 deletions(-) diff --git a/tests/Composer/Test/Fixtures/installer/SAMPLE b/tests/Composer/Test/Fixtures/installer/SAMPLE index 618f6edf2..90afe7058 100644 --- a/tests/Composer/Test/Fixtures/installer/SAMPLE +++ b/tests/Composer/Test/Fixtures/installer/SAMPLE @@ -10,5 +10,7 @@ --INSTALLED:DEV-- ---EXPECT-- or --EXPECT:UPDATE-- or --EXPECT:DEV-- or --EXPECT:UPDATE:DEV-- +--RUN-- +install +--EXPECT-- \ No newline at end of file diff --git a/tests/Composer/Test/Fixtures/installer/aliased-priority-conflicting.test b/tests/Composer/Test/Fixtures/installer/aliased-priority-conflicting.test index 9c015fb9b..1ffa936b4 100644 --- a/tests/Composer/Test/Fixtures/installer/aliased-priority-conflicting.test +++ b/tests/Composer/Test/Fixtures/installer/aliased-priority-conflicting.test @@ -42,6 +42,8 @@ Aliases take precedence over default package even if default is selected "a/req": "dev-feature-foo as dev-master" } } +--RUN-- +install --EXPECT-- Marking a/req (dev-master feat.f) as installed, alias of a/req (dev-feature-foo feat.f) Installing a/req (dev-feature-foo feat.f) diff --git a/tests/Composer/Test/Fixtures/installer/aliased-priority.test b/tests/Composer/Test/Fixtures/installer/aliased-priority.test index 048399584..35af86fcd 100644 --- a/tests/Composer/Test/Fixtures/installer/aliased-priority.test +++ b/tests/Composer/Test/Fixtures/installer/aliased-priority.test @@ -44,6 +44,8 @@ Aliases take precedence over default package "a/c": "dev-feature-foo as dev-master" } } +--RUN-- +install --EXPECT-- Installing a/b (dev-master forked) Marking a/b (1.0.x-dev forked) as installed, alias of a/b (dev-master forked) diff --git a/tests/Composer/Test/Fixtures/installer/install-dev.test b/tests/Composer/Test/Fixtures/installer/install-dev.test index 0dfa1bec1..3b03675bb 100644 --- a/tests/Composer/Test/Fixtures/installer/install-dev.test +++ b/tests/Composer/Test/Fixtures/installer/install-dev.test @@ -18,6 +18,8 @@ Installs a package in dev env "a/b": "1.0.0" } } ---EXPECT:DEV-- +--RUN-- +install --dev +--EXPECT-- Installing a/a (1.0.0) Installing a/b (1.0.0) \ No newline at end of file diff --git a/tests/Composer/Test/Fixtures/installer/install-reference.test b/tests/Composer/Test/Fixtures/installer/install-reference.test index 433b6fcbd..f8e696f99 100644 --- a/tests/Composer/Test/Fixtures/installer/install-reference.test +++ b/tests/Composer/Test/Fixtures/installer/install-reference.test @@ -17,5 +17,7 @@ Installs a dev package forcing it's reference "a/a": "dev-master#def000" } } +--RUN-- +install --EXPECT-- Installing a/a (dev-master def000) diff --git a/tests/Composer/Test/Fixtures/installer/install-simple.test b/tests/Composer/Test/Fixtures/installer/install-simple.test index 6cc46d3aa..008bf76e7 100644 --- a/tests/Composer/Test/Fixtures/installer/install-simple.test +++ b/tests/Composer/Test/Fixtures/installer/install-simple.test @@ -14,5 +14,7 @@ Installs a simple package with exact match requirement "a/a": "1.0.0" } } +--RUN-- +install --EXPECT-- Installing a/a (1.0.0) \ No newline at end of file diff --git a/tests/Composer/Test/Fixtures/installer/update-all.test b/tests/Composer/Test/Fixtures/installer/update-all.test index e7641dbb9..b5806687e 100644 --- a/tests/Composer/Test/Fixtures/installer/update-all.test +++ b/tests/Composer/Test/Fixtures/installer/update-all.test @@ -36,6 +36,8 @@ Updates updateable packages [ { "name": "a/b", "version": "1.0.0" } ] ---EXPECT:UPDATE:DEV-- +--RUN-- +update --dev +--EXPECT-- Updating a/a (1.0.0) to a/a (1.0.1) Updating a/b (1.0.0) to a/b (2.0.0) \ No newline at end of file diff --git a/tests/Composer/Test/Fixtures/installer/update-reference.test b/tests/Composer/Test/Fixtures/installer/update-reference.test index c6418a8eb..9dca245ee 100644 --- a/tests/Composer/Test/Fixtures/installer/update-reference.test +++ b/tests/Composer/Test/Fixtures/installer/update-reference.test @@ -24,5 +24,7 @@ Updates a dev package forcing it's reference "source": { "reference": "abc123", "url": "", "type": "git" } } ] +--RUN-- +install --EXPECT-- Updating a/a (dev-master abc123) to a/a (dev-master def000) diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 6ceaa069e..6de28f45f 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -12,6 +12,7 @@ namespace Composer\Test; use Composer\Installer; +use Composer\Console\Application; use Composer\Config; use Composer\Json\JsonFile; use Composer\Repository\ArrayRepository; @@ -24,6 +25,8 @@ use Composer\Test\Mock\FactoryMock; use Composer\Test\Mock\InstalledFilesystemRepositoryMock; use Composer\Test\Mock\InstallationManagerMock; use Composer\Test\Mock\WritableRepositoryMock; +use Symfony\Component\Console\Input\StringInput; +use Symfony\Component\Console\Output\StreamOutput; class InstallerTest extends TestCase { @@ -121,7 +124,7 @@ class InstallerTest extends TestCase /** * @dataProvider getIntegrationTests */ - public function testIntegration($file, $message, $condition, $composer, $lock, $installed, $installedDev, $update, $dev, $expect) + public function testIntegration($file, $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expect) { if ($condition) { eval('$res = '.$condition.';'); @@ -177,14 +180,31 @@ class InstallerTest extends TestCase $autoloadGenerator ); - $installer->setDevMode($dev)->setUpdate($update); + $application = new Application; + $application->get('install')->setCode(function ($input, $output) use ($installer) { + $installer->setDevMode($input->getOption('dev')); - $result = $installer->run(); - $this->assertTrue($result, $output); + return $installer->run(); + }); - $expectedInstalled = isset($options['install']) ? $options['install'] : array(); - $expectedUpdated = isset($options['update']) ? $options['update'] : array(); - $expectedUninstalled = isset($options['uninstall']) ? $options['uninstall'] : array(); + $application->get('update')->setCode(function ($input, $output) use ($installer) { + $installer + ->setDevMode($input->getOption('dev')) + ->setUpdate(true) + ->setUpdateWhitelist($input->getArgument('packages')); + + return $installer->run(); + }); + + if (!preg_match('{^(install|update)\b}', $run)) { + throw new \UnexpectedValueException('The run command only supports install and update'); + } + + $application->setAutoExit(false); + $appOutput = fopen('php://memory', 'w+'); + $result = $application->run(new StringInput($run), new StreamOutput($appOutput)); + fseek($appOutput, 0); + $this->assertEquals(0, $result, $output . stream_get_contents($appOutput)); $installationManager = $composer->getInstallationManager(); $this->assertSame($expect, implode("\n", $installationManager->getTrace())); @@ -210,7 +230,8 @@ class InstallerTest extends TestCase (?:--LOCK--\s*(?P'.$content.'))?\s* (?:--INSTALLED--\s*(?P'.$content.'))?\s* (?:--INSTALLED:DEV--\s*(?P'.$content.'))?\s* - --EXPECT(?P:UPDATE)?(?P:DEV)?--\s*(?P.*?)\s* + --RUN--\s*(?P.*?)\s* + --EXPECT--\s*(?P.*?)\s* $}xs'; $installed = array(); @@ -231,8 +252,7 @@ class InstallerTest extends TestCase if (!empty($match['installedDev'])) { $installedDev = JsonFile::parseJson($match['installedDev']); } - $update = !empty($match['update']); - $dev = !empty($match['dev']); + $run = $match['run']; $expect = $match['expect']; } catch (\Exception $e) { die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file))); @@ -241,7 +261,7 @@ class InstallerTest extends TestCase die(sprintf('Test "%s" is not valid, did not match the expected format.', str_replace($fixturesDir.'/', '', $file))); } - $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $update, $dev, $expect); + $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expect); } return $tests;