1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Added check for filename in archive manager and added test

This commit is contained in:
MakiCode 2015-10-04 19:53:07 -05:00
parent 87b5af60a8
commit 906c1c2e66
2 changed files with 47 additions and 3 deletions

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()
{
$packageName = $this->manager->getPackageFilename($package);
$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;