2012-08-23 19:35:17 +00:00
|
|
|
<?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;
|
|
|
|
|
2012-08-28 21:55:26 +00:00
|
|
|
use Composer\Factory;
|
|
|
|
use Composer\IO\NullIO;
|
2012-08-23 19:35:17 +00:00
|
|
|
use Composer\Package\Archiver;
|
|
|
|
use Composer\Package\Archiver\ArchiveManager;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Till Klampaeckel <till@php.net>
|
|
|
|
* @author Matthieu Moquet <matthieu@moquet.net>
|
|
|
|
*/
|
|
|
|
class ArchiveManagerTest extends ArchiverTest
|
|
|
|
{
|
|
|
|
protected $manager;
|
2012-10-21 10:16:28 +00:00
|
|
|
protected $targetDir;
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2012-08-28 21:55:26 +00:00
|
|
|
$factory = new Factory();
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager = $factory->createArchiveManager(null, $factory->createConfig());
|
|
|
|
$this->targetDir = sys_get_temp_dir().'/composer_archiver_tests';
|
2012-08-23 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnknownFormat()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('RuntimeException');
|
|
|
|
|
|
|
|
$package = $this->setupPackage();
|
|
|
|
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager->archive($package, '__unknown_format__', $this->targetDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testArchiveTarWithVcs()
|
|
|
|
{
|
|
|
|
$this->setupGitRepo();
|
|
|
|
|
|
|
|
$package = $this->setupPackage();
|
|
|
|
|
|
|
|
// The package is source from git,
|
|
|
|
// so it should `git archive --format tar`
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager->archive($package, 'tar', $this->targetDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
$target = $this->getTargetName($package, 'tar');
|
|
|
|
$this->assertFileExists($target);
|
|
|
|
|
|
|
|
unlink($target);
|
|
|
|
$this->removeGitRepo();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testArchiveTarWithoutVcs()
|
|
|
|
{
|
|
|
|
$this->setupGitRepo();
|
|
|
|
|
|
|
|
$package = $this->setupPackage();
|
|
|
|
|
|
|
|
// This should use the TarArchiver
|
2012-10-21 10:16:28 +00:00
|
|
|
$this->manager->archive($package, 'tar', $this->targetDir);
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
$package->setSourceType('__unknown_type__'); // disable VCS recognition
|
|
|
|
$target = $this->getTargetName($package, 'tar');
|
|
|
|
$this->assertFileExists($target);
|
|
|
|
|
|
|
|
unlink($target);
|
|
|
|
$this->removeGitRepo();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTargetName(PackageInterface $package, $format)
|
|
|
|
{
|
2012-10-21 10:16:28 +00:00
|
|
|
$packageName = $package->getUniqueName();
|
|
|
|
$target = $this->targetDir.'/'.$packageName.'.'.$format;
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
return $target;
|
|
|
|
}
|
|
|
|
}
|