1
0
Fork 0

Refactor InstallerTest to be a bit more future proof

pull/635/merge
Jordi Boggiano 2012-04-29 17:29:06 +02:00
parent 63c6c6d875
commit 7b2d3ff6a2
1 changed files with 22 additions and 22 deletions

View File

@ -25,40 +25,45 @@ class InstallerTest extends TestCase
/** /**
* @dataProvider provideInstaller * @dataProvider provideInstaller
*/ */
public function testInstaller(array $expectedInstalled, array $expectedUpdated, array $expectedUninstalled, PackageInterface $package, RepositoryInterface $repository) public function testInstaller(PackageInterface $rootPackage, $repositories, array $options)
{ {
$io = $this->getMock('Composer\IO\IOInterface'); $io = $this->getMock('Composer\IO\IOInterface');
$package = $this->getPackage('A', '1.0.0');
$package->setRequires(array(
new Link('A', 'B', $this->getVersionConstraint('=', '1.0.0')),
));
$downloadManager = $this->getMock('Composer\Downloader\DownloadManager'); $downloadManager = $this->getMock('Composer\Downloader\DownloadManager');
$config = $this->getMock('Composer\Config'); $config = $this->getMock('Composer\Config');
$repositoryManager = new RepositoryManager($io, $config); $repositoryManager = new RepositoryManager($io, $config);
$repositoryManager->setLocalRepository(new WritableRepositoryMock()); $repositoryManager->setLocalRepository(new WritableRepositoryMock());
$repositoryManager->setLocalDevRepository(new WritableRepositoryMock()); $repositoryManager->setLocalDevRepository(new WritableRepositoryMock());
if (!is_array($repositories)) {
$repositories = array($repositories);
}
foreach ($repositories as $repository) {
$repositoryManager->addRepository($repository); $repositoryManager->addRepository($repository);
}
$locker = $this->getMockBuilder('Composer\Package\Locker')->disableOriginalConstructor()->getMock(); $locker = $this->getMockBuilder('Composer\Package\Locker')->disableOriginalConstructor()->getMock();
$installationManager = new InstallationManagerMock(); $installationManager = new InstallationManagerMock();
$eventDispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock(); $eventDispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock();
$autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator'); $autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator');
$installer = new Installer($io, $package, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator); $installer = new Installer($io, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
$result = $installer->run(); $result = $installer->run();
$this->assertTrue($result); $this->assertTrue($result);
$expectedInstalled = isset($options['install']) ? $options['install'] : array();
$expectedUpdated = isset($options['update']) ? $options['update'] : array();
$expectedUninstalled = isset($options['uninstall']) ? $options['uninstall'] : array();
$installed = $installationManager->getInstalledPackages(); $installed = $installationManager->getInstalledPackages();
$this->assertSame($expectedInstalled, array_map(array($this, 'getPackageString'), $installed)); $this->assertSame($expectedInstalled, $installed);
$updated = $installationManager->getUpdatedPackages(); $updated = $installationManager->getUpdatedPackages();
$this->assertSame($expectedUpdated, array_map(array($this, 'getPackageString'), $updated)); $this->assertSame($expectedUpdated, $updated);
$uninstalled = $installationManager->getUninstalledPackages(); $uninstalled = $installationManager->getUninstalledPackages();
$this->assertSame($expectedUninstalled, array_map(array($this, 'getPackageString'), $uninstalled)); $this->assertSame($expectedUninstalled, $uninstalled);
} }
public function provideInstaller() public function provideInstaller()
@ -78,11 +83,11 @@ class InstallerTest extends TestCase
)); ));
$cases[] = array( $cases[] = array(
array('b-1.0.0.0'),
array(),
array(),
$a, $a,
new ArrayRepository(array($b)), new ArrayRepository(array($b)),
array(
'install' => array($b)
),
); );
// #480: when A requires B and B requires A, and A is a published root package // #480: when A requires B and B requires A, and A is a published root package
@ -98,18 +103,13 @@ class InstallerTest extends TestCase
)); ));
$cases[] = array( $cases[] = array(
array('b-1.0.0.0'),
array(),
array(),
$a, $a,
new ArrayRepository(array($a, $b)), new ArrayRepository(array($a, $b)),
array(
'install' => array($b)
),
); );
return $cases; return $cases;
} }
public function getPackageString(PackageInterface $package)
{
return (string) $package;
}
} }