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;
|
|
|
|
|
2012-08-28 21:55:26 +00:00
|
|
|
use Composer\Factory;
|
2012-08-23 19:35:17 +00:00
|
|
|
use Composer\Package\Archiver;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
|
|
|
|
class ArchiveManagerTest extends ArchiverTest
|
|
|
|
{
|
|
|
|
protected $manager;
|
2012-10-21 10:16:28 +00:00
|
|
|
protected $targetDir;
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2012-08-28 21:55:26 +00:00
|
|
|
$factory = new Factory();
|
2013-02-07 08:39:11 +00:00
|
|
|
$this->manager = $factory->createArchiveManager($factory->createConfig());
|
2012-10-21 16:23:35 +00:00
|
|
|
$this->targetDir = $this->testDir.'/composer_archiver_tests';
|
2012-08-23 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnknownFormat()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('RuntimeException');
|
|
|
|
|
|
|
|
$package = $this->setupPackage();
|
|
|
|
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager->archive($package, '__unknown_format__', $this->targetDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 16:23:35 +00:00
|
|
|
public function testArchiveTar()
|
2012-08-23 19:35:17 +00:00
|
|
|
{
|
|
|
|
$this->setupGitRepo();
|
|
|
|
|
|
|
|
$package = $this->setupPackage();
|
|
|
|
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager->archive($package, 'tar', $this->targetDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
$target = $this->getTargetName($package, 'tar');
|
|
|
|
$this->assertFileExists($target);
|
|
|
|
|
|
|
|
unlink($target);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTargetName(PackageInterface $package, $format)
|
|
|
|
{
|
2013-03-26 11:15:39 +00:00
|
|
|
$packageName = $this->manager->getPackageFilename($package);
|
2012-10-21 10:16:28 +00:00
|
|
|
$target = $this->targetDir.'/'.$packageName.'.'.$format;
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
return $target;
|
|
|
|
}
|
2012-10-21 16:23:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create local git repository to run tests against!
|
|
|
|
*/
|
|
|
|
protected function setupGitRepo()
|
|
|
|
{
|
|
|
|
$currentWorkDir = getcwd();
|
|
|
|
chdir($this->testDir);
|
|
|
|
|
2013-03-28 12:21:55 +00:00
|
|
|
$output = null;
|
|
|
|
$result = $this->process->execute('git init -q', $output, $this->testDir);
|
2012-10-21 16:23:35 +00:00
|
|
|
if ($result > 0) {
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = file_put_contents('b', 'a');
|
|
|
|
if (false === $result) {
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
throw new \RuntimeException('Could not save file.');
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:21:55 +00:00
|
|
|
$result = $this->process->execute('git add b && git commit -m "commit b" -q', $output, $this->testDir);
|
2012-10-21 16:23:35 +00:00
|
|
|
if ($result > 0) {
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
}
|
2012-08-23 19:35:17 +00:00
|
|
|
}
|