1
0
Fork 0

Add tests for the changes in #2690

pull/2733/head
Nils Adermann 2014-02-21 13:14:36 +01:00
parent 3148ffd355
commit ec12b8a675
3 changed files with 56 additions and 4 deletions

View File

@ -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--

View File

@ -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)

View File

@ -138,7 +138,7 @@ class InstallerTest extends TestCase
/** /**
* @dataProvider getIntegrationTests * @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) { if ($condition) {
eval('$res = '.$condition.';'); eval('$res = '.$condition.';');
@ -228,7 +228,7 @@ class InstallerTest extends TestCase
$appOutput = fopen('php://memory', 'w+'); $appOutput = fopen('php://memory', 'w+');
$result = $application->run(new StringInput($run), new StreamOutput($appOutput)); $result = $application->run(new StringInput($run), new StreamOutput($appOutput));
fseek($appOutput, 0); fseek($appOutput, 0);
$this->assertEquals(0, $result, $output . stream_get_contents($appOutput)); $this->assertEquals($expectExitCode, $result, $output . stream_get_contents($appOutput));
if ($expectLock) { if ($expectLock) {
unset($actualLock['hash']); unset($actualLock['hash']);
@ -250,7 +250,7 @@ class InstallerTest extends TestCase
$tests = array(); $tests = array();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { 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; continue;
} }
@ -266,6 +266,7 @@ class InstallerTest extends TestCase
--RUN--\s*(?P<run>.*?)\s* --RUN--\s*(?P<run>.*?)\s*
(?:--EXPECT-LOCK--\s*(?P<expectLock>'.$content.'))?\s* (?:--EXPECT-LOCK--\s*(?P<expectLock>'.$content.'))?\s*
(?:--EXPECT-OUTPUT--\s*(?P<expectOutput>'.$content.'))?\s* (?:--EXPECT-OUTPUT--\s*(?P<expectOutput>'.$content.'))?\s*
(?:--EXPECT-EXIT-CODE--\s*(?P<expectExitCode>\d+))?\s*
--EXPECT--\s*(?P<expect>.*?)\s* --EXPECT--\s*(?P<expect>.*?)\s*
$}xs'; $}xs';
@ -273,6 +274,7 @@ class InstallerTest extends TestCase
$installedDev = array(); $installedDev = array();
$lock = array(); $lock = array();
$expectLock = array(); $expectLock = array();
$expectExitCode = 0;
if (preg_match($pattern, $test, $match)) { if (preg_match($pattern, $test, $match)) {
try { try {
@ -294,6 +296,7 @@ class InstallerTest extends TestCase
} }
$expectOutput = $match['expectOutput']; $expectOutput = $match['expectOutput'];
$expect = $match['expect']; $expect = $match['expect'];
$expectExitCode = $match['expectExitCode'];
} catch (\Exception $e) { } catch (\Exception $e) {
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file))); 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))); 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; return $tests;