Added check for filename in archive manager and added test
parent
87b5af60a8
commit
906c1c2e66
|
@ -108,6 +108,9 @@ class ArchiveManager
|
||||||
if (empty($format)) {
|
if (empty($format)) {
|
||||||
throw new \InvalidArgumentException('Format must be specified');
|
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
|
// Search for the most appropriate archiver
|
||||||
$usableArchiver = null;
|
$usableArchiver = null;
|
||||||
|
@ -124,7 +127,11 @@ class ArchiveManager
|
||||||
}
|
}
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
|
if(null === $fileName) {
|
||||||
|
$packageName = $fileName;
|
||||||
|
} else {
|
||||||
$packageName = $this->getPackageFilename($package);
|
$packageName = $this->getPackageFilename($package);
|
||||||
|
}
|
||||||
|
|
||||||
// Archive filename
|
// Archive filename
|
||||||
$filesystem->ensureDirectoryExists($targetDir);
|
$filesystem->ensureDirectoryExists($targetDir);
|
||||||
|
|
|
@ -13,11 +13,16 @@
|
||||||
namespace Composer\Test\Package\Archiver;
|
namespace Composer\Test\Package\Archiver;
|
||||||
|
|
||||||
use Composer\Factory;
|
use Composer\Factory;
|
||||||
|
use Composer\Package\Archiver\ArchiveManager;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
class ArchiveManagerTest extends ArchiverTest
|
class ArchiveManagerTest extends ArchiverTest
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var ArchiveManager
|
||||||
|
*/
|
||||||
protected $manager;
|
protected $manager;
|
||||||
|
|
||||||
protected $targetDir;
|
protected $targetDir;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
|
@ -55,9 +60,41 @@ class ArchiveManagerTest extends ArchiverTest
|
||||||
unlink($target);
|
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);
|
$packageName = $this->manager->getPackageFilename($package);
|
||||||
|
}
|
||||||
$target = $this->targetDir.'/'.$packageName.'.'.$format;
|
$target = $this->targetDir.'/'.$packageName.'.'.$format;
|
||||||
|
|
||||||
return $target;
|
return $target;
|
||||||
|
|
Loading…
Reference in New Issue