Skip to content

Commit

Permalink
Refactor integration tests to accept any run command
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed May 27, 2012
1 parent 510769c commit 0f9cf8a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
4 changes: 3 additions & 1 deletion tests/Composer/Test/Fixtures/installer/SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<installed.json file definition>
--INSTALLED:DEV--
<installed_dev.json file definition>
--EXPECT-- or --EXPECT:UPDATE-- or --EXPECT:DEV-- or --EXPECT:UPDATE:DEV--
--RUN--
install
--EXPECT--
<output (stringified operations)>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/Composer/Test/Fixtures/installer/aliased-priority.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/Composer/Test/Fixtures/installer/install-dev.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tests/Composer/Test/Fixtures/installer/install-reference.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tests/Composer/Test/Fixtures/installer/install-simple.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion tests/Composer/Test/Fixtures/installer/update-all.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tests/Composer/Test/Fixtures/installer/update-reference.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
42 changes: 31 additions & 11 deletions tests/Composer/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,8 @@
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
{
Expand Down Expand Up @@ -121,7 +124,7 @@ public function provideInstaller()
/**
* @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.';');
Expand Down Expand Up @@ -177,14 +180,31 @@ public function testIntegration($file, $message, $condition, $composer, $lock, $
$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()));
Expand All @@ -210,7 +230,8 @@ public function getIntegrationTests()
(?:--LOCK--\s*(?P<lock>'.$content.'))?\s*
(?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s*
(?:--INSTALLED:DEV--\s*(?P<installedDev>'.$content.'))?\s*
--EXPECT(?P<update>:UPDATE)?(?P<dev>:DEV)?--\s*(?P<expect>.*?)\s*
--RUN--\s*(?P<run>.*?)\s*
--EXPECT--\s*(?P<expect>.*?)\s*
$}xs';

$installed = array();
Expand All @@ -231,8 +252,7 @@ public function getIntegrationTests()
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)));
Expand All @@ -241,7 +261,7 @@ public function getIntegrationTests()
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;
Expand Down

0 comments on commit 0f9cf8a

Please sign in to comment.