Refactor integration tests to accept any run command
parent
9841b6f36e
commit
43150b88a2
|
@ -10,5 +10,7 @@
|
||||||
<installed.json file definition>
|
<installed.json file definition>
|
||||||
--INSTALLED:DEV--
|
--INSTALLED:DEV--
|
||||||
<installed_dev.json file definition>
|
<installed_dev.json file definition>
|
||||||
--EXPECT-- or --EXPECT:UPDATE-- or --EXPECT:DEV-- or --EXPECT:UPDATE:DEV--
|
--RUN--
|
||||||
|
install
|
||||||
|
--EXPECT--
|
||||||
<output (stringified operations)>
|
<output (stringified operations)>
|
|
@ -42,6 +42,8 @@ Aliases take precedence over default package even if default is selected
|
||||||
"a/req": "dev-feature-foo as dev-master"
|
"a/req": "dev-feature-foo as dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Marking a/req (dev-master feat.f) as installed, alias of a/req (dev-feature-foo feat.f)
|
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)
|
Installing a/req (dev-feature-foo feat.f)
|
||||||
|
|
|
@ -44,6 +44,8 @@ Aliases take precedence over default package
|
||||||
"a/c": "dev-feature-foo as dev-master"
|
"a/c": "dev-feature-foo as dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Installing a/b (dev-master forked)
|
Installing a/b (dev-master forked)
|
||||||
Marking a/b (1.0.x-dev forked) as installed, alias of a/b (dev-master forked)
|
Marking a/b (1.0.x-dev forked) as installed, alias of a/b (dev-master forked)
|
||||||
|
|
|
@ -18,6 +18,8 @@ Installs a package in dev env
|
||||||
"a/b": "1.0.0"
|
"a/b": "1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--EXPECT:DEV--
|
--RUN--
|
||||||
|
install --dev
|
||||||
|
--EXPECT--
|
||||||
Installing a/a (1.0.0)
|
Installing a/a (1.0.0)
|
||||||
Installing a/b (1.0.0)
|
Installing a/b (1.0.0)
|
|
@ -17,5 +17,7 @@ Installs a dev package forcing it's reference
|
||||||
"a/a": "dev-master#def000"
|
"a/a": "dev-master#def000"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Installing a/a (dev-master def000)
|
Installing a/a (dev-master def000)
|
||||||
|
|
|
@ -14,5 +14,7 @@ Installs a simple package with exact match requirement
|
||||||
"a/a": "1.0.0"
|
"a/a": "1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Installing a/a (1.0.0)
|
Installing a/a (1.0.0)
|
|
@ -36,6 +36,8 @@ Updates updateable packages
|
||||||
[
|
[
|
||||||
{ "name": "a/b", "version": "1.0.0" }
|
{ "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/a (1.0.0) to a/a (1.0.1)
|
||||||
Updating a/b (1.0.0) to a/b (2.0.0)
|
Updating a/b (1.0.0) to a/b (2.0.0)
|
|
@ -24,5 +24,7 @@ Updates a dev package forcing it's reference
|
||||||
"source": { "reference": "abc123", "url": "", "type": "git" }
|
"source": { "reference": "abc123", "url": "", "type": "git" }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
--RUN--
|
||||||
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Updating a/a (dev-master abc123) to a/a (dev-master def000)
|
Updating a/a (dev-master abc123) to a/a (dev-master def000)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Composer\Test;
|
namespace Composer\Test;
|
||||||
|
|
||||||
use Composer\Installer;
|
use Composer\Installer;
|
||||||
|
use Composer\Console\Application;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\Repository\ArrayRepository;
|
use Composer\Repository\ArrayRepository;
|
||||||
|
@ -24,6 +25,8 @@ use Composer\Test\Mock\FactoryMock;
|
||||||
use Composer\Test\Mock\InstalledFilesystemRepositoryMock;
|
use Composer\Test\Mock\InstalledFilesystemRepositoryMock;
|
||||||
use Composer\Test\Mock\InstallationManagerMock;
|
use Composer\Test\Mock\InstallationManagerMock;
|
||||||
use Composer\Test\Mock\WritableRepositoryMock;
|
use Composer\Test\Mock\WritableRepositoryMock;
|
||||||
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
|
use Symfony\Component\Console\Output\StreamOutput;
|
||||||
|
|
||||||
class InstallerTest extends TestCase
|
class InstallerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -121,7 +124,7 @@ class InstallerTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider getIntegrationTests
|
* @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) {
|
if ($condition) {
|
||||||
eval('$res = '.$condition.';');
|
eval('$res = '.$condition.';');
|
||||||
|
@ -177,14 +180,31 @@ class InstallerTest extends TestCase
|
||||||
$autoloadGenerator
|
$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();
|
return $installer->run();
|
||||||
$this->assertTrue($result, $output);
|
});
|
||||||
|
|
||||||
$expectedInstalled = isset($options['install']) ? $options['install'] : array();
|
$application->get('update')->setCode(function ($input, $output) use ($installer) {
|
||||||
$expectedUpdated = isset($options['update']) ? $options['update'] : array();
|
$installer
|
||||||
$expectedUninstalled = isset($options['uninstall']) ? $options['uninstall'] : array();
|
->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();
|
$installationManager = $composer->getInstallationManager();
|
||||||
$this->assertSame($expect, implode("\n", $installationManager->getTrace()));
|
$this->assertSame($expect, implode("\n", $installationManager->getTrace()));
|
||||||
|
@ -210,7 +230,8 @@ class InstallerTest extends TestCase
|
||||||
(?:--LOCK--\s*(?P<lock>'.$content.'))?\s*
|
(?:--LOCK--\s*(?P<lock>'.$content.'))?\s*
|
||||||
(?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s*
|
(?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s*
|
||||||
(?:--INSTALLED:DEV--\s*(?P<installedDev>'.$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';
|
$}xs';
|
||||||
|
|
||||||
$installed = array();
|
$installed = array();
|
||||||
|
@ -231,8 +252,7 @@ class InstallerTest extends TestCase
|
||||||
if (!empty($match['installedDev'])) {
|
if (!empty($match['installedDev'])) {
|
||||||
$installedDev = JsonFile::parseJson($match['installedDev']);
|
$installedDev = JsonFile::parseJson($match['installedDev']);
|
||||||
}
|
}
|
||||||
$update = !empty($match['update']);
|
$run = $match['run'];
|
||||||
$dev = !empty($match['dev']);
|
|
||||||
$expect = $match['expect'];
|
$expect = $match['expect'];
|
||||||
} 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)));
|
||||||
|
@ -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)));
|
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;
|
return $tests;
|
||||||
|
|
Loading…
Reference in New Issue