2012-08-23 19:35:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Package\Archiver;
|
|
|
|
|
|
|
|
use Composer\Package\Archiver\MercurialArchiver;
|
2012-08-27 08:00:31 +00:00
|
|
|
use Composer\Package\Package;
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Matthieu Moquet <matthieu@moquet.net>
|
|
|
|
* @author Till Klampaeckel <till@php.net>
|
|
|
|
*/
|
|
|
|
class MercurialArchiverTest extends ArchiverTest
|
|
|
|
{
|
|
|
|
public function testZipArchive()
|
|
|
|
{
|
2012-10-21 16:23:35 +00:00
|
|
|
// Set up repository
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->setupMercurialRepo();
|
2012-10-21 16:23:35 +00:00
|
|
|
$package = $this->setupPackage();
|
2012-08-23 19:35:17 +00:00
|
|
|
$target = sys_get_temp_dir().'/composer_archiver_test.zip';
|
|
|
|
|
|
|
|
// Test archive
|
|
|
|
$archiver = new MercurialArchiver();
|
2012-08-28 20:00:28 +00:00
|
|
|
$archiver->archive($package->getSourceUrl(), $target, 'zip', 'default');
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->assertFileExists($target);
|
|
|
|
|
|
|
|
unlink($target);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTarArchive()
|
|
|
|
{
|
2012-10-21 16:23:35 +00:00
|
|
|
// Set up repository
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->setupMercurialRepo();
|
2012-10-21 16:23:35 +00:00
|
|
|
$package = $this->setupPackage();
|
2012-08-23 19:35:17 +00:00
|
|
|
$target = sys_get_temp_dir().'/composer_archiver_test.tar';
|
|
|
|
|
|
|
|
// Test archive
|
|
|
|
$archiver = new MercurialArchiver();
|
2012-08-28 20:00:28 +00:00
|
|
|
$archiver->archive($package->getSourceUrl(), $target, 'tar', 'default');
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->assertFileExists($target);
|
|
|
|
|
|
|
|
unlink($target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-10-21 16:23:35 +00:00
|
|
|
* Create local mercurial repository to run tests against!
|
2012-08-23 19:35:17 +00:00
|
|
|
*/
|
|
|
|
protected function setupMercurialRepo()
|
|
|
|
{
|
|
|
|
$currentWorkDir = getcwd();
|
|
|
|
chdir($this->testDir);
|
|
|
|
|
|
|
|
$result = $this->process->execute('hg init -q');
|
|
|
|
if ($result > 0) {
|
2012-10-21 16:23:35 +00:00
|
|
|
chdir($currentWorkDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = file_put_contents('b', 'a');
|
|
|
|
if (false === $result) {
|
2012-10-21 16:23:35 +00:00
|
|
|
chdir($currentWorkDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not save file.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $this->process->execute('hg add b && hg commit -m "commit b" --config ui.username=test -q');
|
|
|
|
if ($result > 0) {
|
2012-10-21 16:23:35 +00:00
|
|
|
chdir($currentWorkDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
}
|
|
|
|
|
2012-10-21 16:23:35 +00:00
|
|
|
protected function setupPackage()
|
2012-08-23 19:35:17 +00:00
|
|
|
{
|
2012-10-21 16:23:35 +00:00
|
|
|
$package = parent::setupPackage();
|
2012-08-23 19:35:17 +00:00
|
|
|
$package->setSourceReference('default');
|
|
|
|
$package->setSourceType('hg');
|
|
|
|
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
}
|