2012-08-24 08:57:38 +00:00
|
|
|
<?php
|
2012-08-23 19:35:17 +00:00
|
|
|
|
2012-08-24 08:57:38 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-27 07:33:04 +00:00
|
|
|
namespace Composer\Test\Package\Archiver;
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-28 20:32:26 +00:00
|
|
|
use Composer\Package\Archiver\PharArchiver;
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-28 20:32:26 +00:00
|
|
|
class PharArchiverTest extends ArchiverTest
|
2012-08-24 08:57:38 +00:00
|
|
|
{
|
2012-08-28 20:32:26 +00:00
|
|
|
public function testTarArchive()
|
2012-08-24 08:57:38 +00:00
|
|
|
{
|
2012-10-21 16:23:35 +00:00
|
|
|
// Set up repository
|
|
|
|
$this->setupDummyRepo();
|
2012-08-24 08:57:38 +00:00
|
|
|
$package = $this->setupPackage();
|
2012-08-23 19:35:17 +00:00
|
|
|
$target = sys_get_temp_dir().'/composer_archiver_test.tar';
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-23 19:35:17 +00:00
|
|
|
// Test archive
|
2012-08-28 20:32:26 +00:00
|
|
|
$archiver = new PharArchiver();
|
2013-03-26 11:15:39 +00:00
|
|
|
$archiver->archive($package->getSourceUrl(), $target, 'tar', array('foo/bar', 'baz', '!/foo/bar/baz'));
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->assertFileExists($target);
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-23 19:35:17 +00:00
|
|
|
unlink($target);
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
2012-08-28 20:32:26 +00:00
|
|
|
|
|
|
|
public function testZipArchive()
|
|
|
|
{
|
2012-10-21 16:23:35 +00:00
|
|
|
// Set up repository
|
|
|
|
$this->setupDummyRepo();
|
2012-08-28 20:32:26 +00:00
|
|
|
$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);
|
2012-10-21 16:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a local dummy repository to run tests against!
|
|
|
|
*/
|
|
|
|
protected function setupDummyRepo()
|
|
|
|
{
|
|
|
|
$currentWorkDir = getcwd();
|
|
|
|
chdir($this->testDir);
|
|
|
|
|
2013-02-07 14:45:58 +00:00
|
|
|
$this->writeFile('file.txt', 'content', $currentWorkDir);
|
|
|
|
$this->writeFile('foo/bar/baz', 'content', $currentWorkDir);
|
|
|
|
$this->writeFile('foo/bar/ignoreme', 'content', $currentWorkDir);
|
|
|
|
$this->writeFile('x/baz', 'content', $currentWorkDir);
|
|
|
|
$this->writeFile('x/includeme', 'content', $currentWorkDir);
|
|
|
|
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function writeFile($path, $content, $currentWorkDir)
|
|
|
|
{
|
|
|
|
if (!file_exists(dirname($path))) {
|
|
|
|
mkdir(dirname($path), 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = file_put_contents($path, 'a');
|
2012-10-21 16:23:35 +00:00
|
|
|
if (false === $result) {
|
|
|
|
chdir($currentWorkDir);
|
|
|
|
throw new \RuntimeException('Could not save file.');
|
|
|
|
}
|
2012-08-28 20:32:26 +00:00
|
|
|
}
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|