From a733d76b33a4dba221b25694c7038fe9d13db2f3 Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Tue, 28 Aug 2012 22:32:26 +0200 Subject: [PATCH] Merged zip & tar archivers --- .../{TarArchiver.php => PharArchiver.php} | 12 ++++-- src/Composer/Package/Archiver/ZipArchiver.php | 39 ------------------- .../Package/Archiver/ArchiveManagerTest.php | 3 +- ...rArchiverTest.php => PharArchiverTest.php} | 24 ++++++++++-- .../Test/Package/Archiver/ZipArchiverTest.php | 38 ------------------ 5 files changed, 30 insertions(+), 86 deletions(-) rename src/Composer/Package/Archiver/{TarArchiver.php => PharArchiver.php} (67%) delete mode 100644 src/Composer/Package/Archiver/ZipArchiver.php rename tests/Composer/Test/Package/Archiver/{TarArchiverTest.php => PharArchiverTest.php} (56%) delete mode 100644 tests/Composer/Test/Package/Archiver/ZipArchiverTest.php diff --git a/src/Composer/Package/Archiver/TarArchiver.php b/src/Composer/Package/Archiver/PharArchiver.php similarity index 67% rename from src/Composer/Package/Archiver/TarArchiver.php rename to src/Composer/Package/Archiver/PharArchiver.php index a7c4e9b36..f8a369b52 100644 --- a/src/Composer/Package/Archiver/TarArchiver.php +++ b/src/Composer/Package/Archiver/PharArchiver.php @@ -19,14 +19,20 @@ use Composer\Package\PackageInterface; * @author Till Klampaeckel * @author Matthieu Moquet */ -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)); } } diff --git a/src/Composer/Package/Archiver/ZipArchiver.php b/src/Composer/Package/Archiver/ZipArchiver.php deleted file mode 100644 index 1664b2a8d..000000000 --- a/src/Composer/Package/Archiver/ZipArchiver.php +++ /dev/null @@ -1,39 +0,0 @@ - - * Jordi Boggiano - * - * 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 - * @author Matthieu Moquet - */ -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; - } -} diff --git a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php index 75f1259c5..34c595991 100644 --- a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php @@ -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() diff --git a/tests/Composer/Test/Package/Archiver/TarArchiverTest.php b/tests/Composer/Test/Package/Archiver/PharArchiverTest.php similarity index 56% rename from tests/Composer/Test/Package/Archiver/TarArchiverTest.php rename to tests/Composer/Test/Package/Archiver/PharArchiverTest.php index faab116ef..625626b28 100644 --- a/tests/Composer/Test/Package/Archiver/TarArchiverTest.php +++ b/tests/Composer/Test/Package/Archiver/PharArchiverTest.php @@ -12,15 +12,15 @@ namespace Composer\Test\Package\Archiver; -use Composer\Package\Archiver\TarArchiver; +use Composer\Package\Archiver\PharArchiver; /** * @author Till Klampaeckel * @author Matthieu Moquet */ -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(); + } } diff --git a/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php b/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php deleted file mode 100644 index ed919b21a..000000000 --- a/tests/Composer/Test/Package/Archiver/ZipArchiverTest.php +++ /dev/null @@ -1,38 +0,0 @@ - - * Jordi Boggiano - * - * 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 - * @author Matthieu Moquet - */ -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(); - } -}