1
0
Fork 0

Use unique cache dir for integration tests as well

pull/5144/head
Jordi Boggiano 2016-04-01 12:07:42 +01:00
parent 1bd9c8da3c
commit eb84ca564f
3 changed files with 25 additions and 17 deletions

View File

@ -15,6 +15,7 @@ namespace Composer\Test;
use Composer\Installer; use Composer\Installer;
use Composer\Console\Application; use Composer\Console\Application;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Util\Filesystem;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Repository\InstalledArrayRepository; use Composer\Repository\InstalledArrayRepository;
@ -34,6 +35,7 @@ use Composer\IO\BufferIO;
class InstallerTest extends TestCase class InstallerTest extends TestCase
{ {
protected $prevCwd; protected $prevCwd;
protected $tempComposerHome;
public function setUp() public function setUp()
{ {
@ -44,6 +46,10 @@ class InstallerTest extends TestCase
public function tearDown() public function tearDown()
{ {
chdir($this->prevCwd); 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 // Create Composer mock object according to configuration
$composer = FactoryMock::create($io, $composerConfig); $composer = FactoryMock::create($io, $composerConfig);
$this->tempComposerHome = $composer->getConfig()->get('home');
$jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock(); $jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
$jsonMock->expects($this->any()) $jsonMock->expects($this->any())

View File

@ -18,6 +18,7 @@ use Composer\Repository\RepositoryManager;
use Composer\Repository\WritableRepositoryInterface; use Composer\Repository\WritableRepositoryInterface;
use Composer\Installer; use Composer\Installer;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\TestCase;
class FactoryMock extends Factory class FactoryMock extends Factory
{ {
@ -26,7 +27,7 @@ class FactoryMock extends Factory
$config = new Config(true, $cwd); $config = new Config(true, $cwd);
$config->merge(array( $config->merge(array(
'config' => array('home' => sys_get_temp_dir().'/composer-test'), 'config' => array('home' => TestCase::getUniqueTmpDirectory()),
'repositories' => array('packagist' => false), 'repositories' => array('packagist' => false),
)); ));

View File

@ -22,6 +22,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
{ {
private static $parser; 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() protected static function getVersionParser()
{ {
if (!self::$parser) { if (!self::$parser) {
@ -57,22 +73,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
return new AliasPackage($package, $normVersion, $version); 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) protected static function ensureDirectoryExistsAndClear($directory)
{ {
$fs = new Filesystem(); $fs = new Filesystem();