1
0
Fork 0

Merge remote-tracking branch 'chx/913'

pull/2292/head
Jordi Boggiano 2013-09-25 20:58:13 +02:00
commit a813867065
4 changed files with 46 additions and 16 deletions

View File

@ -41,15 +41,16 @@ class LibraryInstaller implements InstallerInterface
* @param IOInterface $io * @param IOInterface $io
* @param Composer $composer * @param Composer $composer
* @param string $type * @param string $type
* @param Filesystem $filesystem
*/ */
public function __construct(IOInterface $io, Composer $composer, $type = 'library') public function __construct(IOInterface $io, Composer $composer, $type = 'library', Filesystem $filesystem = null)
{ {
$this->composer = $composer; $this->composer = $composer;
$this->downloadManager = $composer->getDownloadManager(); $this->downloadManager = $composer->getDownloadManager();
$this->io = $io; $this->io = $io;
$this->type = $type; $this->type = $type;
$this->filesystem = new Filesystem(); $this->filesystem = $filesystem ?: new Filesystem();
$this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/'); $this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');
$this->binDir = rtrim($composer->getConfig()->get('bin-dir'), '/'); $this->binDir = rtrim($composer->getConfig()->get('bin-dir'), '/');
} }
@ -157,8 +158,12 @@ class LibraryInstaller implements InstallerInterface
protected function updateCode(PackageInterface $initial, PackageInterface $target) protected function updateCode(PackageInterface $initial, PackageInterface $target)
{ {
$downloadPath = $this->getInstallPath($initial); $initialDownloadPath = $this->getInstallPath($initial);
$this->downloadManager->update($initial, $target, $downloadPath); $targetDownloadPath = $this->getInstallPath($target);
if ($targetDownloadPath !== $initialDownloadPath) {
$this->filesystem->copyThenRemove($initialDownloadPath, $targetDownloadPath);
}
$this->downloadManager->update($initial, $target, $targetDownloadPath);
} }
protected function removeCode(PackageInterface $package) protected function removeCode(PackageInterface $package)

View File

@ -129,15 +129,12 @@ class Filesystem
{ {
$it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS); $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST); $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
$this->ensureDirectoryExists($target);
if (!file_exists($target)) {
mkdir($target, 0777, true);
}
foreach ($ri as $file) { foreach ($ri as $file) {
$targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName(); $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
if ($file->isDir()) { if ($file->isDir()) {
mkdir($targetPath); $this->ensureDirectoryExists($targetPath);
} else { } else {
copy($file->getPathname(), $targetPath); copy($file->getPathname(), $targetPath);
} }

View File

@ -131,15 +131,31 @@ class LibraryInstallerTest extends TestCase
*/ */
public function testUpdate() public function testUpdate()
{ {
$library = new LibraryInstaller($this->io, $this->composer); $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')
->getMock();
$filesystem
->expects($this->once())
->method('copyThenRemove')
->with($this->vendorDir.'/package1', $this->vendorDir.'/package1/newtarget');
$initial = $this->createPackageMock(); $initial = $this->createPackageMock();
$target = $this->createPackageMock(); $target = $this->createPackageMock();
$initial $initial
->expects($this->any()) ->expects($this->once())
->method('getPrettyName') ->method('getPrettyName')
->will($this->returnValue('package1')); ->will($this->returnValue('package1'));
$target
->expects($this->once())
->method('getPrettyName')
->will($this->returnValue('package1'));
$target
->expects($this->once())
->method('getTargetDir')
->will($this->returnValue('newtarget'));
$this->repository $this->repository
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('hasPackage') ->method('hasPackage')
@ -148,7 +164,7 @@ class LibraryInstallerTest extends TestCase
$this->dm $this->dm
->expects($this->once()) ->expects($this->once())
->method('update') ->method('update')
->with($initial, $target, $this->vendorDir.'/package1'); ->with($initial, $target, $this->vendorDir.'/package1/newtarget');
$this->repository $this->repository
->expects($this->once()) ->expects($this->once())
@ -160,6 +176,7 @@ class LibraryInstallerTest extends TestCase
->method('addPackage') ->method('addPackage')
->with($target); ->with($target);
$library = new LibraryInstaller($this->io, $this->composer, 'library', $filesystem);
$library->update($this->repository, $initial, $target); $library->update($this->repository, $initial, $target);
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created'); $this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
$this->assertFileExists($this->binDir, 'Bin dir should be created'); $this->assertFileExists($this->binDir, 'Bin dir should be created');

View File

@ -20,6 +20,7 @@ use Composer\Package\Loader\ArrayLoader;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Plugin\PluginManager; use Composer\Plugin\PluginManager;
use Composer\Autoload\AutoloadGenerator; use Composer\Autoload\AutoloadGenerator;
use Composer\Util\Filesystem;
class PluginInstallerTest extends \PHPUnit_Framework_TestCase class PluginInstallerTest extends \PHPUnit_Framework_TestCase
{ {
@ -30,13 +31,17 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
protected $repository; protected $repository;
protected $io; protected $io;
protected $autoloadGenerator; protected $autoloadGenerator;
protected $directory;
protected function setUp() protected function setUp()
{ {
$loader = new JsonLoader(new ArrayLoader()); $loader = new JsonLoader(new ArrayLoader());
$this->packages = array(); $this->packages = array();
$this->directory = sys_get_temp_dir() . '/' . uniqid();
for ($i = 1; $i <= 4; $i++) { for ($i = 1; $i <= 4; $i++) {
$this->packages[] = $loader->load(__DIR__.'/Fixtures/plugin-v'.$i.'/composer.json'); $filename = '/Fixtures/plugin-v'.$i.'/composer.json';
mkdir(dirname($this->directory . $filename), 0777, TRUE);
$this->packages[] = $loader->load(__DIR__ . $filename);
} }
$dm = $this->getMockBuilder('Composer\Downloader\DownloadManager') $dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
@ -77,13 +82,19 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase
$config->merge(array( $config->merge(array(
'config' => array( 'config' => array(
'vendor-dir' => __DIR__.'/Fixtures/', 'vendor-dir' => $this->directory.'/Fixtures/',
'home' => __DIR__.'/Fixtures', 'home' => $this->directory.'/Fixtures',
'bin-dir' => __DIR__.'/Fixtures/bin', 'bin-dir' => $this->directory.'/Fixtures/bin',
), ),
)); ));
} }
protected function tearDown()
{
$filesystem = new Filesystem();
$filesystem->removeDirectory($this->directory);
}
public function testInstallNewPlugin() public function testInstallNewPlugin()
{ {
$this->repository $this->repository