Use unique cache dir for integration tests as well
parent
1bd9c8da3c
commit
eb84ca564f
|
@ -15,6 +15,7 @@ namespace Composer\Test;
|
|||
use Composer\Installer;
|
||||
use Composer\Console\Application;
|
||||
use Composer\Json\JsonFile;
|
||||
use Composer\Util\Filesystem;
|
||||
use Composer\Repository\ArrayRepository;
|
||||
use Composer\Repository\RepositoryManager;
|
||||
use Composer\Repository\InstalledArrayRepository;
|
||||
|
@ -34,6 +35,7 @@ use Composer\IO\BufferIO;
|
|||
class InstallerTest extends TestCase
|
||||
{
|
||||
protected $prevCwd;
|
||||
protected $tempComposerHome;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
@ -44,6 +46,10 @@ class InstallerTest extends TestCase
|
|||
public function tearDown()
|
||||
{
|
||||
chdir($this->prevCwd);
|
||||
if (is_dir($this->tempComposerHome)) {
|
||||
$fs = new Filesystem;
|
||||
$fs->removeDirectory($this->tempComposerHome);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,6 +165,7 @@ class InstallerTest extends TestCase
|
|||
|
||||
// Create Composer mock object according to configuration
|
||||
$composer = FactoryMock::create($io, $composerConfig);
|
||||
$this->tempComposerHome = $composer->getConfig()->get('home');
|
||||
|
||||
$jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
|
||||
$jsonMock->expects($this->any())
|
||||
|
|
|
@ -18,6 +18,7 @@ use Composer\Repository\RepositoryManager;
|
|||
use Composer\Repository\WritableRepositoryInterface;
|
||||
use Composer\Installer;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\TestCase;
|
||||
|
||||
class FactoryMock extends Factory
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ class FactoryMock extends Factory
|
|||
$config = new Config(true, $cwd);
|
||||
|
||||
$config->merge(array(
|
||||
'config' => array('home' => sys_get_temp_dir().'/composer-test'),
|
||||
'config' => array('home' => TestCase::getUniqueTmpDirectory()),
|
||||
'repositories' => array('packagist' => false),
|
||||
));
|
||||
|
||||
|
|
|
@ -22,6 +22,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
private static $parser;
|
||||
|
||||
public static function getUniqueTmpDirectory()
|
||||
{
|
||||
$attempts = 5;
|
||||
$root = sys_get_temp_dir();
|
||||
|
||||
do {
|
||||
$unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-' . rand(1000, 9000));
|
||||
|
||||
if (!file_exists($unique) && Silencer::call('mkdir', $unique, 0777)) {
|
||||
return realpath($unique);
|
||||
}
|
||||
} while (--$attempts);
|
||||
|
||||
throw new \RuntimeException('Failed to create a unique temporary directory.');
|
||||
}
|
||||
|
||||
protected static function getVersionParser()
|
||||
{
|
||||
if (!self::$parser) {
|
||||
|
@ -57,22 +73,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
|||
return new AliasPackage($package, $normVersion, $version);
|
||||
}
|
||||
|
||||
protected static function getUniqueTmpDirectory()
|
||||
{
|
||||
$attempts = 5;
|
||||
$root = sys_get_temp_dir();
|
||||
|
||||
do {
|
||||
$unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-' . rand(1000, 9000));
|
||||
|
||||
if (!file_exists($unique) && Silencer::call('mkdir', $unique, 0777)) {
|
||||
return realpath($unique);
|
||||
}
|
||||
} while (--$attempts);
|
||||
|
||||
throw new \RuntimeException('Failed to create a unique temporary directory.');
|
||||
}
|
||||
|
||||
protected static function ensureDirectoryExistsAndClear($directory)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
|
Loading…
Reference in New Issue