1
0
Fork 0

Added check for filename in archive manager and added test

pull/4479/head
MakiCode 2015-10-04 19:53:07 -05:00
parent 87b5af60a8
commit 906c1c2e66
2 changed files with 47 additions and 3 deletions

View File

@ -108,6 +108,9 @@ class ArchiveManager
if (empty($format)) {
throw new \InvalidArgumentException('Format must be specified');
}
if(!is_null($fileName) && !is_string($fileName)) {
throw new \InvalidArgumentException('fileName must be a string');
}
// Search for the most appropriate archiver
$usableArchiver = null;
@ -124,7 +127,11 @@ class ArchiveManager
}
$filesystem = new Filesystem();
if(null === $fileName) {
$packageName = $fileName;
} else {
$packageName = $this->getPackageFilename($package);
}
// Archive filename
$filesystem->ensureDirectoryExists($targetDir);

View File

@ -13,11 +13,16 @@
namespace Composer\Test\Package\Archiver;
use Composer\Factory;
use Composer\Package\Archiver\ArchiveManager;
use Composer\Package\PackageInterface;
class ArchiveManagerTest extends ArchiverTest
{
/**
* @var ArchiveManager
*/
protected $manager;
protected $targetDir;
public function setUp()
@ -55,9 +60,41 @@ class ArchiveManagerTest extends ArchiverTest
unlink($target);
}
protected function getTargetName(PackageInterface $package, $format)
public function testArchiveCustomFileName()
{
$this->setupGitRepo();
$package = $this->setupPackage();
$fileName = "testArchiveName";
$this->manager->archive($package, 'tar', $this->targetDir, $fileName);
$target = $this->getTargetName($package, 'tar', $fileName);
$this->assertFileExists($target);
$tmppath = sys_get_temp_dir().'/composer_archiver/'.$this->manager->getPackageFilename($package);
$this->assertFileNotExists($tmppath);
unlink($target);
}
public function testNonStringFileName() {
$this->setExpectedException("InvalidArgumentException");
$package = $this->setupPackage();
$this->manager->archive($package, 'tar', $this->targetDir, array());
}
protected function getTargetName(PackageInterface $package, $format, $fileName = null)
{
if(!is_null($fileName)) {
$packageName = $fileName;
} else {
$packageName = $this->manager->getPackageFilename($package);
}
$target = $this->targetDir.'/'.$packageName.'.'.$format;
return $target;