1
0
Fork 0
composer/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php

92 lines
2.2 KiB
PHP
Raw Normal View History

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;
protected $workDir;
public function setUp()
{
parent::setUp();
2012-08-28 21:55:26 +00:00
$factory = new Factory();
2012-08-23 19:35:17 +00:00
2012-08-28 21:55:26 +00:00
$this->workDir = sys_get_temp_dir();
$this->manager = $factory->createArchiveManager($this->workDir);
2012-08-23 19:35:17 +00:00
}
public function testUnknownFormat()
{
$this->setExpectedException('RuntimeException');
$package = $this->setupPackage();
$this->manager->archive($package, '__unknown_format__');
}
public function testArchiveTarWithVcs()
{
$this->setupGitRepo();
$package = $this->setupPackage();
// The package is source from git,
// so it should `git archive --format tar`
$this->manager->archive($package, 'tar');
$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
$this->manager->archive($package, 'tar');
$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)
{
$packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName());
$target = $this->workDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
return $target;
}
}