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
|
|
|
|
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
use Composer\Util\ProcessExecutor;
|
2012-08-23 19:35:17 +00:00
|
|
|
use Composer\Package\MemoryPackage;
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-23 19:35:17 +00:00
|
|
|
/**
|
|
|
|
* @author Till Klampaeckel <till@php.net>
|
|
|
|
* @author Matthieu Moquet <matthieu@moquet.net>
|
|
|
|
*/
|
2012-08-27 07:33:04 +00:00
|
|
|
abstract class ArchiverTest extends \PHPUnit_Framework_TestCase
|
2012-08-24 08:57:38 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Composer\Util\Filesystem
|
|
|
|
*/
|
2012-08-23 19:35:17 +00:00
|
|
|
protected $filesystem;
|
2012-08-24 08:57:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Composer\Util\ProcessExecutor
|
|
|
|
*/
|
|
|
|
protected $process;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-08-23 19:35:17 +00:00
|
|
|
protected $testDir;
|
2012-08-24 08:57:38 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->filesystem = new Filesystem();
|
|
|
|
$this->process = new ProcessExecutor();
|
|
|
|
$this->testDir = sys_get_temp_dir().'/composer_archivertest_git_repository'.mt_rand();
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create local git repository to run tests against!
|
|
|
|
*/
|
|
|
|
protected function setupGitRepo()
|
|
|
|
{
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->filesystem->removeDirectory($this->testDir);
|
|
|
|
$this->filesystem->ensureDirectoryExists($this->testDir);
|
2012-08-24 08:57:38 +00:00
|
|
|
|
|
|
|
$currentWorkDir = getcwd();
|
2012-08-23 19:35:17 +00:00
|
|
|
chdir($this->testDir);
|
2012-08-24 08:57:38 +00:00
|
|
|
|
2012-08-23 19:35:17 +00:00
|
|
|
$result = $this->process->execute('git init -q');
|
2012-08-24 08:57:38 +00:00
|
|
|
if ($result > 0) {
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput());
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
2012-08-23 19:35:17 +00:00
|
|
|
|
2012-08-24 08:57:38 +00:00
|
|
|
$result = file_put_contents('b', 'a');
|
|
|
|
if (false === $result) {
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not save file.');
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
2012-08-23 19:35:17 +00:00
|
|
|
|
|
|
|
$result = $this->process->execute('git add b && git commit -m "commit b" -q');
|
2012-08-24 08:57:38 +00:00
|
|
|
if ($result > 0) {
|
2012-08-23 19:35:17 +00:00
|
|
|
throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
2012-08-23 19:35:17 +00:00
|
|
|
|
2012-08-24 08:57:38 +00:00
|
|
|
chdir($currentWorkDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function removeGitRepo()
|
|
|
|
{
|
2012-08-23 19:35:17 +00:00
|
|
|
$this->filesystem->removeDirectory($this->testDir);
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function setupPackage()
|
|
|
|
{
|
2012-08-27 07:33:04 +00:00
|
|
|
$package = new MemoryPackage('archivertest/archivertest', 'master', 'master');
|
2012-08-23 19:35:17 +00:00
|
|
|
$package->setSourceUrl(realpath($this->testDir));
|
2012-08-24 08:57:38 +00:00
|
|
|
$package->setSourceReference('master');
|
|
|
|
$package->setSourceType('git');
|
|
|
|
|
2012-08-23 19:35:17 +00:00
|
|
|
return $package;
|
2012-08-24 08:57:38 +00:00
|
|
|
}
|
|
|
|
}
|