Merged zip & tar archivers

main
Matthieu Moquet 12 years ago committed by Nils Adermann
parent b21bb1dcc5
commit a733d76b33

@ -19,14 +19,20 @@ use Composer\Package\PackageInterface;
* @author Till Klampaeckel <till@php.net>
* @author Matthieu Moquet <matthieu@moquet.net>
*/
class TarArchiver extends BaseArchiver
class PharArchiver extends BaseArchiver
{
static public $formats = array(
'zip' => \Phar::ZIP,
'tar' => \Phar::TAR,
);
/**
* {@inheritdoc}
*/
public function archive($sources, $target, $format, $sourceRef = null)
{
$this->createPharArchive($sources, $target, \Phar::TAR);
// source reference is useless for this archiver
$this->createPharArchive($sources, $target, static::$formats[$format]);
}
/**
@ -34,6 +40,6 @@ class TarArchiver extends BaseArchiver
*/
public function supports($format, $sourceType)
{
return 'tar' === $format;
return in_array($format, array_keys(static::$formats));
}
}

@ -1,39 +0,0 @@
<?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\Package\Archiver;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
/**
* @author Till Klampaeckel <till@php.net>
* @author Matthieu Moquet <matthieu@moquet.net>
*/
class ZipArchiver extends BaseArchiver
{
/**
* {@inheritdoc}
*/
public function archive($sources, $target, $format, $sourceRef = null)
{
$this->createPharArchive($sources, $target, \Phar::ZIP);
}
/**
* {@inheritdoc}
*/
public function supports($format, $sourceType)
{
return 'zip' === $format;
}
}

@ -35,8 +35,7 @@ class ArchiveManagerTest extends ArchiverTest
$this->manager = new ArchiveManager($this->workDir);
$this->manager->addArchiver(new Archiver\GitArchiver);
$this->manager->addArchiver(new Archiver\MercurialArchiver);
$this->manager->addArchiver(new Archiver\TarArchiver);
$this->manager->addArchiver(new Archiver\ZipArchiver);
$this->manager->addArchiver(new Archiver\PharArchiver);
}
public function testUnknownFormat()

@ -12,15 +12,15 @@
namespace Composer\Test\Package\Archiver;
use Composer\Package\Archiver\TarArchiver;
use Composer\Package\Archiver\PharArchiver;
/**
* @author Till Klampaeckel <till@php.net>
* @author Matthieu Moquet <matthieu@moquet.net>
*/
class TarArchiverTest extends ArchiverTest
class PharArchiverTest extends ArchiverTest
{
public function testArchive()
public function testTarArchive()
{
$this->setupGitRepo();
@ -28,11 +28,27 @@ class TarArchiverTest extends ArchiverTest
$target = sys_get_temp_dir().'/composer_archiver_test.tar';
// Test archive
$archiver = new TarArchiver();
$archiver = new PharArchiver();
$archiver->archive($package->getSourceUrl(), $target, 'tar');
$this->assertFileExists($target);
unlink($target);
$this->removeGitRepo();
}
public function testZipArchive()
{
$this->setupGitRepo();
$package = $this->setupPackage();
$target = sys_get_temp_dir().'/composer_archiver_test.zip';
// Test archive
$archiver = new PharArchiver();
$archiver->archive($package->getSourceUrl(), $target, 'zip');
$this->assertFileExists($target);
unlink($target);
$this->removeGitRepo();
}
}

@ -1,38 +0,0 @@
<?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\ZipArchiver;
/**
* @author Till Klampaeckel <till@php.net>
* @author Matthieu Moquet <matthieu@moquet.net>
*/
class ZipArchiverTest extends ArchiverTest
{
public function testArchive()
{
$this->setupGitRepo();
$package = $this->setupPackage();
$target = sys_get_temp_dir().'/composer_archiver_test.zip';
// Test archive
$archiver = new ZipArchiver();
$archiver->archive($package->getSourceUrl(), $target, 'zip');
$this->assertFileExists($target);
unlink($target);
$this->removeGitRepo();
}
}
Loading…
Cancel
Save