From ec12b8a675aa3eb4ed11809c95e2cf8e6ce804b3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 21 Feb 2014 13:14:36 +0100 Subject: [PATCH] Add tests for the changes in #2690 --- .../installer/broken-deps-do-not-replace.test | 25 +++++++++++++++++++ .../installer/replace-root-require.test | 24 ++++++++++++++++++ tests/Composer/Test/InstallerTest.php | 11 +++++--- 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/broken-deps-do-not-replace.test create mode 100644 tests/Composer/Test/Fixtures/installer/replace-root-require.test diff --git a/tests/Composer/Test/Fixtures/installer/broken-deps-do-not-replace.test b/tests/Composer/Test/Fixtures/installer/broken-deps-do-not-replace.test new file mode 100644 index 000000000..c626db198 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/broken-deps-do-not-replace.test @@ -0,0 +1,25 @@ +--TEST-- +Broken dependencies should not lead to a replacer being installed which is not mentioned by name +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.0.0" }, + { "name": "b/b", "version": "1.0.0", "require": {"c/c": "1.*"} }, + { "name": "c/c", "version": "1.0.0", "replace": {"a/a": "1.0.0" },"require":{"x/x": "1.0"}}, + { "name": "d/d", "version": "1.0.0", "replace": {"a/a": "1.0.0", "c/c":"1.0.0" }} + ] + } + ], + "require": { + "a/a": "1.*", + "b/b": "1.*" + } +} +--RUN-- +install +--EXPECT-EXIT-CODE-- +2 +--EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/replace-root-require.test b/tests/Composer/Test/Fixtures/installer/replace-root-require.test new file mode 100644 index 000000000..c00ac4fd5 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/replace-root-require.test @@ -0,0 +1,24 @@ +--TEST-- +Ensure a transiently required replacer can replace root requirements +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "a/a", "version": "1.0.0" }, + { "name": "b/b", "version": "1.0.0", "require": {"c/c": "1.*"} }, + { "name": "c/c", "version": "1.0.0", "replace": {"a/a": "1.0.0" }} + ] + } + ], + "require": { + "a/a": "1.*", + "b/b": "1.*" + } +} +--RUN-- +install +--EXPECT-- +Installing c/c (1.0.0) +Installing b/b (1.0.0) diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 0cc17cfb0..9f2a1bc4b 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -138,7 +138,7 @@ class InstallerTest extends TestCase /** * @dataProvider getIntegrationTests */ - public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect) + public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectExitCode) { if ($condition) { eval('$res = '.$condition.';'); @@ -228,7 +228,7 @@ class InstallerTest extends TestCase $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)); + $this->assertEquals($expectExitCode, $result, $output . stream_get_contents($appOutput)); if ($expectLock) { unset($actualLock['hash']); @@ -250,7 +250,7 @@ class InstallerTest extends TestCase $tests = array(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { - if (!preg_match('/\.test$/', $file)) { + if (!preg_match('/replace-root-require\.test$/', $file)) { continue; } @@ -266,6 +266,7 @@ class InstallerTest extends TestCase --RUN--\s*(?P.*?)\s* (?:--EXPECT-LOCK--\s*(?P'.$content.'))?\s* (?:--EXPECT-OUTPUT--\s*(?P'.$content.'))?\s* + (?:--EXPECT-EXIT-CODE--\s*(?P\d+))?\s* --EXPECT--\s*(?P.*?)\s* $}xs'; @@ -273,6 +274,7 @@ class InstallerTest extends TestCase $installedDev = array(); $lock = array(); $expectLock = array(); + $expectExitCode = 0; if (preg_match($pattern, $test, $match)) { try { @@ -294,6 +296,7 @@ class InstallerTest extends TestCase } $expectOutput = $match['expectOutput']; $expect = $match['expect']; + $expectExitCode = $match['expectExitCode']; } catch (\Exception $e) { die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file))); } @@ -301,7 +304,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, $run, $expectLock, $expectOutput, $expect); + $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectExitCode); } return $tests;