Browse Source

try to use unique test directories

any tests that use the filesystem should have their own unique directory, as we run our test suite in parallel and
cleanup of tests (removing directories) should not interfere with currently running tests
Rob Bast 9 years ago
parent
commit
adf3b956d0
25 changed files with 145 additions and 91 deletions
  1. 12 7
      tests/Composer/Test/AllFunctionalTest.php
  2. 2 2
      tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
  3. 5 10
      tests/Composer/Test/Autoload/ClassMapGeneratorTest.php
  4. 3 3
      tests/Composer/Test/CacheTest.php
  5. 3 3
      tests/Composer/Test/Config/JsonConfigSourceTest.php
  6. 6 13
      tests/Composer/Test/Downloader/FileDownloaderTest.php
  7. 4 3
      tests/Composer/Test/Downloader/GitDownloaderTest.php
  8. 3 2
      tests/Composer/Test/Downloader/HgDownloaderTest.php
  9. 3 2
      tests/Composer/Test/Downloader/PearPackageExtractorTest.php
  10. 3 2
      tests/Composer/Test/Downloader/PerforceDownloaderTest.php
  11. 4 3
      tests/Composer/Test/Downloader/XzDownloaderTest.php
  12. 4 2
      tests/Composer/Test/Downloader/ZipDownloaderTest.php
  13. 5 4
      tests/Composer/Test/Installer/LibraryInstallerTest.php
  14. 3 2
      tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php
  15. 3 3
      tests/Composer/Test/Package/Archiver/ArchiverTest.php
  16. 4 4
      tests/Composer/Test/Package/Archiver/PharArchiverTest.php
  17. 1 1
      tests/Composer/Test/Plugin/PluginInstallerTest.php
  18. 1 1
      tests/Composer/Test/Repository/FilesystemRepositoryTest.php
  19. 6 3
      tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php
  20. 17 4
      tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
  21. 4 2
      tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php
  22. 24 8
      tests/Composer/Test/Repository/Vcs/SvnDriverTest.php
  23. 4 3
      tests/Composer/Test/Repository/VcsRepositoryTest.php
  24. 3 3
      tests/Composer/Test/Util/FilesystemTest.php
  25. 18 1
      tests/Composer/TestCase.php

+ 12 - 7
tests/Composer/Test/AllFunctionalTest.php

@@ -12,14 +12,15 @@
 
 
 namespace Composer\Test;
 namespace Composer\Test;
 
 
-use Symfony\Component\Process\Process;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Symfony\Component\Finder\Finder;
 use Symfony\Component\Finder\Finder;
+use Symfony\Component\Process\Process;
 
 
 /**
 /**
  * @group slow
  * @group slow
  */
  */
-class AllFunctionalTest extends \PHPUnit_Framework_TestCase
+class AllFunctionalTest extends TestCase
 {
 {
     protected $oldcwd;
     protected $oldcwd;
     protected $oldenv;
     protected $oldenv;
@@ -29,17 +30,21 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
     public function setUp()
     public function setUp()
     {
     {
         $this->oldcwd = getcwd();
         $this->oldcwd = getcwd();
+
         chdir(__DIR__.'/Fixtures/functional');
         chdir(__DIR__.'/Fixtures/functional');
     }
     }
 
 
     public function tearDown()
     public function tearDown()
     {
     {
         chdir($this->oldcwd);
         chdir($this->oldcwd);
+
         $fs = new Filesystem;
         $fs = new Filesystem;
+
         if ($this->testDir) {
         if ($this->testDir) {
             $fs->removeDirectory($this->testDir);
             $fs->removeDirectory($this->testDir);
             $this->testDir = null;
             $this->testDir = null;
         }
         }
+
         if ($this->oldenv) {
         if ($this->oldenv) {
             $fs->removeDirectory(getenv('COMPOSER_HOME'));
             $fs->removeDirectory(getenv('COMPOSER_HOME'));
             $_SERVER['COMPOSER_HOME'] = $this->oldenv;
             $_SERVER['COMPOSER_HOME'] = $this->oldenv;
@@ -50,7 +55,7 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
 
 
     public static function setUpBeforeClass()
     public static function setUpBeforeClass()
     {
     {
-        self::$pharPath = sys_get_temp_dir().'/composer-phar-test/composer.phar';
+        self::$pharPath = self::getUniqueTmpDirectory() . '/composer.phar';
     }
     }
 
 
     public static function tearDownAfterClass()
     public static function tearDownAfterClass()
@@ -66,9 +71,7 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
         }
         }
 
 
         $target = dirname(self::$pharPath);
         $target = dirname(self::$pharPath);
-        $fs = new Filesystem;
-        $fs->removeDirectory($target);
-        $fs->ensureDirectoryExists($target);
+        $fs = new Filesystem();
         chdir($target);
         chdir($target);
 
 
         $it = new \RecursiveDirectoryIterator(__DIR__.'/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
         $it = new \RecursiveDirectoryIterator(__DIR__.'/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
@@ -85,9 +88,11 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
 
 
         $proc = new Process('php '.escapeshellarg('./bin/compile'), $target);
         $proc = new Process('php '.escapeshellarg('./bin/compile'), $target);
         $exitcode = $proc->run();
         $exitcode = $proc->run();
+
         if ($exitcode !== 0 || trim($proc->getOutput())) {
         if ($exitcode !== 0 || trim($proc->getOutput())) {
             $this->fail($proc->getOutput());
             $this->fail($proc->getOutput());
         }
         }
+
         $this->assertTrue(file_exists(self::$pharPath));
         $this->assertTrue(file_exists(self::$pharPath));
     }
     }
 
 
@@ -140,7 +145,7 @@ class AllFunctionalTest extends \PHPUnit_Framework_TestCase
         $data = array();
         $data = array();
         $section = null;
         $section = null;
 
 
-        $testDir = sys_get_temp_dir().'/composer_functional_test'.uniqid(mt_rand(), true);
+        $testDir = self::getUniqueTmpDirectory();
         $this->testDir = $testDir;
         $this->testDir = $testDir;
         $varRegex = '#%([a-zA-Z_-]+)%#';
         $varRegex = '#%([a-zA-Z_-]+)%#';
         $variableReplacer = function ($match) use (&$data, $testDir) {
         $variableReplacer = function ($match) use (&$data, $testDir) {

+ 2 - 2
tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

@@ -88,8 +88,7 @@ class AutoloadGeneratorTest extends TestCase
         $this->fs = new Filesystem;
         $this->fs = new Filesystem;
         $that = $this;
         $that = $this;
 
 
-        $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
-        $this->fs->ensureDirectoryExists($this->workingDir);
+        $this->workingDir = $this->getUniqueTmpDirectory();
         $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
         $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
         $this->ensureDirectoryExistsAndClear($this->vendorDir);
         $this->ensureDirectoryExistsAndClear($this->vendorDir);
 
 
@@ -144,6 +143,7 @@ class AutoloadGeneratorTest extends TestCase
         if (is_dir($this->workingDir)) {
         if (is_dir($this->workingDir)) {
             $this->fs->removeDirectory($this->workingDir);
             $this->fs->removeDirectory($this->workingDir);
         }
         }
+
         if (is_dir($this->vendorDir)) {
         if (is_dir($this->vendorDir)) {
             $this->fs->removeDirectory($this->vendorDir);
             $this->fs->removeDirectory($this->vendorDir);
         }
         }

+ 5 - 10
tests/Composer/Test/Autoload/ClassMapGeneratorTest.php

@@ -19,10 +19,11 @@
 namespace Composer\Test\Autoload;
 namespace Composer\Test\Autoload;
 
 
 use Composer\Autoload\ClassMapGenerator;
 use Composer\Autoload\ClassMapGenerator;
+use Composer\TestCase;
 use Symfony\Component\Finder\Finder;
 use Symfony\Component\Finder\Finder;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
+class ClassMapGeneratorTest extends TestCase
 {
 {
     /**
     /**
      * @dataProvider getTestCreateMapTests
      * @dataProvider getTestCreateMapTests
@@ -127,10 +128,8 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
     {
     {
         $this->checkIfFinderIsAvailable();
         $this->checkIfFinderIsAvailable();
 
 
-        $tempDir = sys_get_temp_dir().'/ComposerTestAmbiguousRefs';
-        if (!is_dir($tempDir.'/other')) {
-            mkdir($tempDir.'/other', 0777, true);
-        }
+        $tempDir = $this->getUniqueTmpDirectory();
+        $this->ensureDirectoryExistsAndClear($tempDir.'/other');
 
 
         $finder = new Finder();
         $finder = new Finder();
         $finder->files()->in($tempDir);
         $finder->files()->in($tempDir);
@@ -171,13 +170,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
      */
      */
     public function testUnambiguousReference()
     public function testUnambiguousReference()
     {
     {
-        $tempDir = sys_get_temp_dir().'/ComposerTestUnambiguousRefs';
-        if (!is_dir($tempDir)) {
-            mkdir($tempDir, 0777, true);
-        }
+        $tempDir = $this->getUniqueTmpDirectory();
 
 
         file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
         file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
-
         file_put_contents(
         file_put_contents(
             $tempDir.'/B.php',
             $tempDir.'/B.php',
             "<?php
             "<?php

+ 3 - 3
tests/Composer/Test/CacheTest.php

@@ -25,15 +25,15 @@ class CacheTest extends TestCase
             $this->markTestSkipped('Test causes intermittent failures on Travis');
             $this->markTestSkipped('Test causes intermittent failures on Travis');
         }
         }
 
 
-        $this->root = sys_get_temp_dir() . '/composer_testdir';
-        $this->ensureDirectoryExistsAndClear($this->root);
-
+        $this->root = $this->getUniqueTmpDirectory();
         $this->files = array();
         $this->files = array();
         $zeros = str_repeat('0', 1000);
         $zeros = str_repeat('0', 1000);
+
         for ($i = 0; $i < 4; $i++) {
         for ($i = 0; $i < 4; $i++) {
             file_put_contents("{$this->root}/cached.file{$i}.zip", $zeros);
             file_put_contents("{$this->root}/cached.file{$i}.zip", $zeros);
             $this->files[] = new \SplFileInfo("{$this->root}/cached.file{$i}.zip");
             $this->files[] = new \SplFileInfo("{$this->root}/cached.file{$i}.zip");
         }
         }
+
         $this->finder = $this->getMockBuilder('Symfony\Component\Finder\Finder')->disableOriginalConstructor()->getMock();
         $this->finder = $this->getMockBuilder('Symfony\Component\Finder\Finder')->disableOriginalConstructor()->getMock();
 
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $io = $this->getMock('Composer\IO\IOInterface');

+ 3 - 3
tests/Composer/Test/Config/JsonConfigSourceTest.php

@@ -14,9 +14,10 @@ namespace Composer\Test\Json;
 
 
 use Composer\Config\JsonConfigSource;
 use Composer\Config\JsonConfigSource;
 use Composer\Json\JsonFile;
 use Composer\Json\JsonFile;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
+class JsonConfigSourceTest extends TestCase
 {
 {
     /** @var Filesystem */
     /** @var Filesystem */
     private $fs;
     private $fs;
@@ -31,8 +32,7 @@ class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
     protected function setUp()
     protected function setUp()
     {
     {
         $this->fs = new Filesystem;
         $this->fs = new Filesystem;
-        $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest';
-        $this->fs->ensureDirectoryExists($this->workingDir);
+        $this->workingDir = $this->getUniqueTmpDirectory();
     }
     }
 
 
     protected function tearDown()
     protected function tearDown()

+ 6 - 13
tests/Composer/Test/Downloader/FileDownloaderTest.php

@@ -13,9 +13,10 @@
 namespace Composer\Test\Downloader;
 namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\FileDownloader;
 use Composer\Downloader\FileDownloader;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class FileDownloaderTest extends \PHPUnit_Framework_TestCase
+class FileDownloaderTest extends TestCase
 {
 {
     protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $rfs = null, $filesystem = null)
     protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $rfs = null, $filesystem = null)
     {
     {
@@ -53,9 +54,9 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
             ->will($this->returnValue(array('url')))
             ->will($this->returnValue(array('url')))
         ;
         ;
 
 
-        $path = tempnam(sys_get_temp_dir(), 'c');
-
+        $path = tempnam($this->getUniqueTmpDirectory(), 'c');
         $downloader = $this->getDownloader();
         $downloader = $this->getDownloader();
+
         try {
         try {
             $downloader->download($packageMock, $path);
             $downloader->download($packageMock, $path);
             $this->fail();
             $this->fail();
@@ -102,10 +103,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
             ->will($this->returnValue(array()))
             ->will($this->returnValue(array()))
         ;
         ;
 
 
-        do {
-            $path = sys_get_temp_dir().'/'.md5(time().mt_rand());
-        } while (file_exists($path));
-
+        $path = $this->getUniqueTmpDirectory();
         $ioMock = $this->getMock('Composer\IO\IOInterface');
         $ioMock = $this->getMock('Composer\IO\IOInterface');
         $ioMock->expects($this->any())
         $ioMock->expects($this->any())
             ->method('write')
             ->method('write')
@@ -187,14 +185,9 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
         ;
         ;
         $filesystem = $this->getMock('Composer\Util\Filesystem');
         $filesystem = $this->getMock('Composer\Util\Filesystem');
 
 
-        do {
-            $path = sys_get_temp_dir().'/'.md5(time().mt_rand());
-        } while (file_exists($path));
-
+        $path = $this->getUniqueTmpDirectory();
         $downloader = $this->getDownloader(null, null, null, null, null, $filesystem);
         $downloader = $this->getDownloader(null, null, null, null, null, $filesystem);
-
         // make sure the file expected to be downloaded is on disk already
         // make sure the file expected to be downloaded is on disk already
-        mkdir($path, 0777, true);
         touch($path.'/script.js');
         touch($path.'/script.js');
 
 
         try {
         try {

+ 4 - 3
tests/Composer/Test/Downloader/GitDownloaderTest.php

@@ -14,9 +14,10 @@ namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\GitDownloader;
 use Composer\Downloader\GitDownloader;
 use Composer\Config;
 use Composer\Config;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class GitDownloaderTest extends \PHPUnit_Framework_TestCase
+class GitDownloaderTest extends TestCase
 {
 {
     /** @var Filesystem */
     /** @var Filesystem */
     private $fs;
     private $fs;
@@ -26,7 +27,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
     protected function setUp()
     protected function setUp()
     {
     {
         $this->fs = new Filesystem;
         $this->fs = new Filesystem;
-        $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
+        $this->workingDir = $this->getUniqueTmpDirectory();
     }
     }
 
 
     protected function tearDown()
     protected function tearDown()
@@ -317,7 +318,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
             ->method('execute')
             ->method('execute')
             ->with($this->equalTo($expectedGitUpdateCommand))
             ->with($this->equalTo($expectedGitUpdateCommand))
             ->will($this->returnValue(1));
             ->will($this->returnValue(1));
-        
+
         $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
         $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
         $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
         $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
         $downloader->update($packageMock, $packageMock, $this->workingDir);
         $downloader->update($packageMock, $packageMock, $this->workingDir);

+ 3 - 2
tests/Composer/Test/Downloader/HgDownloaderTest.php

@@ -13,16 +13,17 @@
 namespace Composer\Test\Downloader;
 namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\HgDownloader;
 use Composer\Downloader\HgDownloader;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class HgDownloaderTest extends \PHPUnit_Framework_TestCase
+class HgDownloaderTest extends TestCase
 {
 {
     /** @var string */
     /** @var string */
     private $workingDir;
     private $workingDir;
 
 
     protected function setUp()
     protected function setUp()
     {
     {
-        $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
+        $this->workingDir = $this->getUniqueTmpDirectory();
     }
     }
 
 
     protected function tearDown()
     protected function tearDown()

+ 3 - 2
tests/Composer/Test/Downloader/PearPackageExtractorTest.php

@@ -13,8 +13,9 @@
 namespace Composer\Test\Downloader;
 namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\PearPackageExtractor;
 use Composer\Downloader\PearPackageExtractor;
+use Composer\TestCase;
 
 
-class PearPackageExtractorTest extends \PHPUnit_Framework_TestCase
+class PearPackageExtractorTest extends TestCase
 {
 {
     public function testShouldExtractPackage_1_0()
     public function testShouldExtractPackage_1_0()
     {
     {
@@ -122,7 +123,7 @@ class PearPackageExtractorTest extends \PHPUnit_Framework_TestCase
 
 
     public function testShouldPerformReplacements()
     public function testShouldPerformReplacements()
     {
     {
-        $from = tempnam(sys_get_temp_dir(), 'pear-extract');
+        $from = tempnam($this->getUniqueTmpDirectory(), 'pear-extract');
         $to = $from.'-to';
         $to = $from.'-to';
 
 
         $original = 'replaced: @placeholder@; not replaced: @another@; replaced again: @placeholder@';
         $original = 'replaced: @placeholder@; not replaced: @another@; replaced again: @placeholder@';

+ 3 - 2
tests/Composer/Test/Downloader/PerforceDownloaderTest.php

@@ -16,12 +16,13 @@ use Composer\Downloader\PerforceDownloader;
 use Composer\Config;
 use Composer\Config;
 use Composer\Repository\VcsRepository;
 use Composer\Repository\VcsRepository;
 use Composer\IO\IOInterface;
 use Composer\IO\IOInterface;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
 /**
 /**
  * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  */
  */
-class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
+class PerforceDownloaderTest extends TestCase
 {
 {
     protected $config;
     protected $config;
     protected $downloader;
     protected $downloader;
@@ -34,7 +35,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
 
 
     protected function setUp()
     protected function setUp()
     {
     {
-        $this->testPath        = sys_get_temp_dir() . '/composer-test';
+        $this->testPath        = $this->getUniqueTmpDirectory();
         $this->repoConfig      = $this->getRepoConfig();
         $this->repoConfig      = $this->getRepoConfig();
         $this->config          = $this->getConfig();
         $this->config          = $this->getConfig();
         $this->io              = $this->getMockIoInterface();
         $this->io              = $this->getMockIoInterface();

+ 4 - 3
tests/Composer/Test/Downloader/XzDownloaderTest.php

@@ -13,10 +13,11 @@
 namespace Composer\Test\Downloader;
 namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\XzDownloader;
 use Composer\Downloader\XzDownloader;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Composer\Util\RemoteFilesystem;
 use Composer\Util\RemoteFilesystem;
 
 
-class XzDownloaderTest extends \PHPUnit_Framework_TestCase
+class XzDownloaderTest extends TestCase
 {
 {
     /**
     /**
      * @var Filesystem
      * @var Filesystem
@@ -33,7 +34,7 @@ class XzDownloaderTest extends \PHPUnit_Framework_TestCase
         if (defined('PHP_WINDOWS_VERSION_BUILD')) {
         if (defined('PHP_WINDOWS_VERSION_BUILD')) {
             $this->markTestSkipped('Skip test on Windows');
             $this->markTestSkipped('Skip test on Windows');
         }
         }
-        $this->testDir = sys_get_temp_dir().'/composer-xz-test-vendor';
+        $this->testDir = $this->getUniqueTmpDirectory();
     }
     }
 
 
     public function tearDown()
     public function tearDown()
@@ -67,7 +68,7 @@ class XzDownloaderTest extends \PHPUnit_Framework_TestCase
         $downloader = new XzDownloader($io, $config, null, null, null, new RemoteFilesystem($io));
         $downloader = new XzDownloader($io, $config, null, null, null, new RemoteFilesystem($io));
 
 
         try {
         try {
-            $downloader->download($packageMock, sys_get_temp_dir().'/composer-xz-test');
+            $downloader->download($packageMock, $this->getUniqueTmpDirectory());
             $this->fail('Download of invalid tarball should throw an exception');
             $this->fail('Download of invalid tarball should throw an exception');
         } catch (\RuntimeException $e) {
         } catch (\RuntimeException $e) {
             $this->assertContains('File format not recognized', $e->getMessage());
             $this->assertContains('File format not recognized', $e->getMessage());

+ 4 - 2
tests/Composer/Test/Downloader/ZipDownloaderTest.php

@@ -13,9 +13,10 @@
 namespace Composer\Test\Downloader;
 namespace Composer\Test\Downloader;
 
 
 use Composer\Downloader\ZipDownloader;
 use Composer\Downloader\ZipDownloader;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 
 
-class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
+class ZipDownloaderTest extends TestCase
 {
 {
 
 
     /**
     /**
@@ -28,7 +29,8 @@ class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
         if (!class_exists('ZipArchive')) {
         if (!class_exists('ZipArchive')) {
             $this->markTestSkipped('zip extension missing');
             $this->markTestSkipped('zip extension missing');
         }
         }
-        $this->testDir = sys_get_temp_dir().'/composer-zip-test-vendor';
+
+        $this->testDir = $this->getUniqueTmpDirectory();
     }
     }
 
 
     public function tearDown()
     public function tearDown()

+ 5 - 4
tests/Composer/Test/Installer/LibraryInstallerTest.php

@@ -22,6 +22,7 @@ class LibraryInstallerTest extends TestCase
 {
 {
     protected $composer;
     protected $composer;
     protected $config;
     protected $config;
+    protected $rootDir;
     protected $vendorDir;
     protected $vendorDir;
     protected $binDir;
     protected $binDir;
     protected $dm;
     protected $dm;
@@ -37,10 +38,11 @@ class LibraryInstallerTest extends TestCase
         $this->config = new Config();
         $this->config = new Config();
         $this->composer->setConfig($this->config);
         $this->composer->setConfig($this->config);
 
 
-        $this->vendorDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-vendor';
+        $this->rootDir = $this->getUniqueTmpDirectory();
+        $this->vendorDir = $this->rootDir.'/vendor';
         $this->ensureDirectoryExistsAndClear($this->vendorDir);
         $this->ensureDirectoryExistsAndClear($this->vendorDir);
 
 
-        $this->binDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-bin';
+        $this->binDir = $this->rootDir.'/bin';
         $this->ensureDirectoryExistsAndClear($this->binDir);
         $this->ensureDirectoryExistsAndClear($this->binDir);
 
 
         $this->config->merge(array(
         $this->config->merge(array(
@@ -61,8 +63,7 @@ class LibraryInstallerTest extends TestCase
 
 
     protected function tearDown()
     protected function tearDown()
     {
     {
-        $this->fs->removeDirectory($this->vendorDir);
-        $this->fs->removeDirectory($this->binDir);
+        $this->fs->removeDirectory($this->rootDir);
     }
     }
 
 
     public function testInstallerCreationShouldNotCreateVendorDirectory()
     public function testInstallerCreationShouldNotCreateVendorDirectory()

+ 3 - 2
tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php

@@ -13,11 +13,12 @@
 namespace Composer\Test\Package\Archiver;
 namespace Composer\Test\Package\Archiver;
 
 
 use Composer\Package\Archiver\ArchivableFilesFinder;
 use Composer\Package\Archiver\ArchivableFilesFinder;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Symfony\Component\Process\Process;
 use Symfony\Component\Process\Process;
 use Symfony\Component\Process\ExecutableFinder;
 use Symfony\Component\Process\ExecutableFinder;
 
 
-class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
+class ArchivableFilesFinderTest extends TestCase
 {
 {
     protected $sources;
     protected $sources;
     protected $finder;
     protected $finder;
@@ -29,7 +30,7 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
         $this->fs = $fs;
         $this->fs = $fs;
 
 
         $this->sources = $fs->normalizePath(
         $this->sources = $fs->normalizePath(
-            realpath(sys_get_temp_dir()).'/composer_archiver_test'.uniqid(mt_rand(), true)
+            $this->getUniqueTmpDirectory()
         );
         );
 
 
         $fileTree = array(
         $fileTree = array(

+ 3 - 3
tests/Composer/Test/Package/Archiver/ArchiverTest.php

@@ -12,11 +12,12 @@
 
 
 namespace Composer\Test\Package\Archiver;
 namespace Composer\Test\Package\Archiver;
 
 
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Composer\Util\ProcessExecutor;
 use Composer\Util\ProcessExecutor;
 use Composer\Package\Package;
 use Composer\Package\Package;
 
 
-abstract class ArchiverTest extends \PHPUnit_Framework_TestCase
+abstract class ArchiverTest extends TestCase
 {
 {
     /**
     /**
      * @var \Composer\Util\Filesystem
      * @var \Composer\Util\Filesystem
@@ -37,8 +38,7 @@ abstract class ArchiverTest extends \PHPUnit_Framework_TestCase
     {
     {
         $this->filesystem = new Filesystem();
         $this->filesystem = new Filesystem();
         $this->process    = new ProcessExecutor();
         $this->process    = new ProcessExecutor();
-        $this->testDir    = sys_get_temp_dir().'/composer_archiver_test_'.mt_rand();
-        $this->filesystem->ensureDirectoryExists($this->testDir);
+        $this->testDir    = $this->getUniqueTmpDirectory();
     }
     }
 
 
     public function tearDown()
     public function tearDown()

+ 4 - 4
tests/Composer/Test/Package/Archiver/PharArchiverTest.php

@@ -21,14 +21,14 @@ class PharArchiverTest extends ArchiverTest
         // Set up repository
         // Set up repository
         $this->setupDummyRepo();
         $this->setupDummyRepo();
         $package = $this->setupPackage();
         $package = $this->setupPackage();
-        $target  = sys_get_temp_dir().'/composer_archiver_test.tar';
+        $target  = $this->getUniqueTmpDirectory().'/composer_archiver_test.tar';
 
 
         // Test archive
         // Test archive
         $archiver = new PharArchiver();
         $archiver = new PharArchiver();
         $archiver->archive($package->getSourceUrl(), $target, 'tar', array('foo/bar', 'baz', '!/foo/bar/baz'));
         $archiver->archive($package->getSourceUrl(), $target, 'tar', array('foo/bar', 'baz', '!/foo/bar/baz'));
         $this->assertFileExists($target);
         $this->assertFileExists($target);
 
 
-        unlink($target);
+        $this->filesystem->removeDirectory(dirname($target));
     }
     }
 
 
     public function testZipArchive()
     public function testZipArchive()
@@ -36,14 +36,14 @@ class PharArchiverTest extends ArchiverTest
         // Set up repository
         // Set up repository
         $this->setupDummyRepo();
         $this->setupDummyRepo();
         $package = $this->setupPackage();
         $package = $this->setupPackage();
-        $target  = sys_get_temp_dir().'/composer_archiver_test.zip';
+        $target  = $this->getUniqueTmpDirectory().'/composer_archiver_test.zip';
 
 
         // Test archive
         // Test archive
         $archiver = new PharArchiver();
         $archiver = new PharArchiver();
         $archiver->archive($package->getSourceUrl(), $target, 'zip');
         $archiver->archive($package->getSourceUrl(), $target, 'zip');
         $this->assertFileExists($target);
         $this->assertFileExists($target);
 
 
-        unlink($target);
+        $this->filesystem->removeDirectory(dirname($target));
     }
     }
 
 
     /**
     /**

+ 1 - 1
tests/Composer/Test/Plugin/PluginInstallerTest.php

@@ -69,7 +69,7 @@ class PluginInstallerTest extends TestCase
     {
     {
         $loader = new JsonLoader(new ArrayLoader());
         $loader = new JsonLoader(new ArrayLoader());
         $this->packages = array();
         $this->packages = array();
-        $this->directory = sys_get_temp_dir() . '/' . uniqid();
+        $this->directory = $this->getUniqueTmpDirectory();
         for ($i = 1; $i <= 7; $i++) {
         for ($i = 1; $i <= 7; $i++) {
             $filename = '/Fixtures/plugin-v'.$i.'/composer.json';
             $filename = '/Fixtures/plugin-v'.$i.'/composer.json';
             mkdir(dirname($this->directory . $filename), 0777, true);
             mkdir(dirname($this->directory . $filename), 0777, true);

+ 1 - 1
tests/Composer/Test/Repository/FilesystemRepositoryTest.php

@@ -42,7 +42,7 @@ class FilesystemRepositoryTest extends TestCase
     }
     }
 
 
     /**
     /**
-     * @expectedException Composer\Repository\InvalidRepositoryException
+     * @expectedException \Composer\Repository\InvalidRepositoryException
      */
      */
     public function testCorruptedRepositoryFile()
     public function testCorruptedRepositoryFile()
     {
     {

+ 6 - 3
tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php

@@ -14,19 +14,22 @@ namespace Composer\Test\Repository\Vcs;
 
 
 use Composer\Downloader\TransportException;
 use Composer\Downloader\TransportException;
 use Composer\Repository\Vcs\GitHubDriver;
 use Composer\Repository\Vcs\GitHubDriver;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Composer\Config;
 use Composer\Config;
 
 
-class GitHubDriverTest extends \PHPUnit_Framework_TestCase
+class GitHubDriverTest extends TestCase
 {
 {
+    private $home;
     private $config;
     private $config;
 
 
     public function setUp()
     public function setUp()
     {
     {
+        $this->home = $this->getUniqueTmpDirectory();
         $this->config = new Config();
         $this->config = new Config();
         $this->config->merge(array(
         $this->config->merge(array(
             'config' => array(
             'config' => array(
-                'home' => sys_get_temp_dir() . '/composer-test',
+                'home' => $this->home,
             ),
             ),
         ));
         ));
     }
     }
@@ -34,7 +37,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
     public function tearDown()
     public function tearDown()
     {
     {
         $fs = new Filesystem;
         $fs = new Filesystem;
-        $fs->removeDirectory(sys_get_temp_dir() . '/composer-test');
+        $fs->removeDirectory($this->home);
     }
     }
 
 
     public function testPrivateRepository()
     public function testPrivateRepository()

+ 17 - 4
tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php

@@ -14,29 +14,42 @@ namespace Composer\Test\Repository\Vcs;
 
 
 use Composer\Repository\Vcs\GitLabDriver;
 use Composer\Repository\Vcs\GitLabDriver;
 use Composer\Config;
 use Composer\Config;
+use Composer\TestCase;
+use Composer\Util\Filesystem;
 
 
 /**
 /**
  * @author Jérôme Tamarelle <jerome@tamarelle.net>
  * @author Jérôme Tamarelle <jerome@tamarelle.net>
  */
  */
-class GitLabDriverTest extends \PHPUnit_Framework_TestCase
+class GitLabDriverTest extends TestCase
 {
 {
+    private $home;
+    private $config;
+    private $io;
+    private $process;
+    private $remoteFilesystem;
+
     public function setUp()
     public function setUp()
     {
     {
+        $this->home = $this->getUniqueTmpDirectory();
         $this->config = new Config();
         $this->config = new Config();
         $this->config->merge(array(
         $this->config->merge(array(
             'config' => array(
             'config' => array(
-                'home' => sys_get_temp_dir().'/composer-test',
+                'home' => $this->home,
                 'gitlab-domains' => array('mycompany.com/gitlab', 'gitlab.com')
                 'gitlab-domains' => array('mycompany.com/gitlab', 'gitlab.com')
             ),
             ),
         ));
         ));
 
 
         $this->io = $this->prophesize('Composer\IO\IOInterface');
         $this->io = $this->prophesize('Composer\IO\IOInterface');
-
         $this->process = $this->prophesize('Composer\Util\ProcessExecutor');
         $this->process = $this->prophesize('Composer\Util\ProcessExecutor');
-
         $this->remoteFilesystem = $this->prophesize('Composer\Util\RemoteFilesystem');
         $this->remoteFilesystem = $this->prophesize('Composer\Util\RemoteFilesystem');
     }
     }
 
 
+    public function tearDown()
+    {
+        $fs = new Filesystem();
+        $fs->removeDirectory($this->home);
+    }
+
     public function getInitializeUrls()
     public function getInitializeUrls()
     {
     {
         return array(
         return array(

+ 4 - 2
tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php

@@ -13,6 +13,7 @@
 namespace Composer\Test\Repository\Vcs;
 namespace Composer\Test\Repository\Vcs;
 
 
 use Composer\Repository\Vcs\PerforceDriver;
 use Composer\Repository\Vcs\PerforceDriver;
+use Composer\TestCase;
 use Composer\Util\Filesystem;
 use Composer\Util\Filesystem;
 use Composer\Config;
 use Composer\Config;
 use Composer\Util\Perforce;
 use Composer\Util\Perforce;
@@ -20,7 +21,7 @@ use Composer\Util\Perforce;
 /**
 /**
  * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  */
  */
-class PerforceDriverTest extends \PHPUnit_Framework_TestCase
+class PerforceDriverTest extends TestCase
 {
 {
     protected $config;
     protected $config;
     protected $io;
     protected $io;
@@ -29,6 +30,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
     protected $testPath;
     protected $testPath;
     protected $driver;
     protected $driver;
     protected $repoConfig;
     protected $repoConfig;
+    protected $perforce;
 
 
     const TEST_URL    = 'TEST_PERFORCE_URL';
     const TEST_URL    = 'TEST_PERFORCE_URL';
     const TEST_DEPOT  = 'TEST_DEPOT_CONFIG';
     const TEST_DEPOT  = 'TEST_DEPOT_CONFIG';
@@ -36,7 +38,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
 
 
     protected function setUp()
     protected function setUp()
     {
     {
-        $this->testPath         = sys_get_temp_dir() . '/composer-test';
+        $this->testPath         = $this->getUniqueTmpDirectory();
         $this->config           = $this->getTestConfig($this->testPath);
         $this->config           = $this->getTestConfig($this->testPath);
         $this->repoConfig       = $this->getTestRepoConfig();
         $this->repoConfig       = $this->getTestRepoConfig();
         $this->io               = $this->getMockIOInterface();
         $this->io               = $this->getMockIOInterface();

+ 24 - 8
tests/Composer/Test/Repository/Vcs/SvnDriverTest.php

@@ -14,9 +14,31 @@ namespace Composer\Test\Repository\Vcs;
 
 
 use Composer\Repository\Vcs\SvnDriver;
 use Composer\Repository\Vcs\SvnDriver;
 use Composer\Config;
 use Composer\Config;
+use Composer\TestCase;
+use Composer\Util\Filesystem;
 
 
-class SvnDriverTest extends \PHPUnit_Framework_TestCase
+class SvnDriverTest extends TestCase
 {
 {
+    protected $home;
+    protected $config;
+
+    public function setUp()
+    {
+        $this->home = $this->getUniqueTmpDirectory();
+        $this->config = new Config();
+        $this->config->merge(array(
+            'config' => array(
+                'home' => $this->home,
+            ),
+        ));
+    }
+
+    public function tearDown()
+    {
+        $fs = new Filesystem();
+        $fs->removeDirectory($this->home);
+    }
+
     /**
     /**
      * @expectedException RuntimeException
      * @expectedException RuntimeException
      */
      */
@@ -39,17 +61,11 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase
             ->method('execute')
             ->method('execute')
             ->will($this->returnValue(0));
             ->will($this->returnValue(0));
 
 
-        $config = new Config();
-        $config->merge(array(
-            'config' => array(
-                'home' => sys_get_temp_dir() . '/composer-test',
-            ),
-        ));
         $repoConfig = array(
         $repoConfig = array(
             'url' => 'http://till:secret@corp.svn.local/repo',
             'url' => 'http://till:secret@corp.svn.local/repo',
         );
         );
 
 
-        $svn = new SvnDriver($repoConfig, $console, $config, $process);
+        $svn = new SvnDriver($repoConfig, $console, $this->config, $process);
         $svn->initialize();
         $svn->initialize();
     }
     }
 
 

+ 4 - 3
tests/Composer/Test/Repository/VcsRepositoryTest.php

@@ -12,6 +12,7 @@
 
 
 namespace Composer\Test\Repository;
 namespace Composer\Test\Repository;
 
 
+use Composer\TestCase;
 use Symfony\Component\Process\ExecutableFinder;
 use Symfony\Component\Process\ExecutableFinder;
 use Composer\Package\Dumper\ArrayDumper;
 use Composer\Package\Dumper\ArrayDumper;
 use Composer\Repository\VcsRepository;
 use Composer\Repository\VcsRepository;
@@ -23,7 +24,7 @@ use Composer\Config;
 /**
 /**
  * @group slow
  * @group slow
  */
  */
-class VcsRepositoryTest extends \PHPUnit_Framework_TestCase
+class VcsRepositoryTest extends TestCase
 {
 {
     private static $composerHome;
     private static $composerHome;
     private static $gitRepo;
     private static $gitRepo;
@@ -32,8 +33,8 @@ class VcsRepositoryTest extends \PHPUnit_Framework_TestCase
     protected function initialize()
     protected function initialize()
     {
     {
         $oldCwd = getcwd();
         $oldCwd = getcwd();
-        self::$composerHome = sys_get_temp_dir() . '/composer-home-'.mt_rand().'/';
-        self::$gitRepo = sys_get_temp_dir() . '/composer-git-'.mt_rand().'/';
+        self::$composerHome = $this->getUniqueTmpDirectory();
+        self::$gitRepo = $this->getUniqueTmpDirectory();
 
 
         $locator = new ExecutableFinder();
         $locator = new ExecutableFinder();
         if (!$locator->find('git')) {
         if (!$locator->find('git')) {

+ 3 - 3
tests/Composer/Test/Util/FilesystemTest.php

@@ -44,8 +44,8 @@ class FilesystemTest extends TestCase
     public function setUp()
     public function setUp()
     {
     {
         $this->fs = new Filesystem;
         $this->fs = new Filesystem;
-        $this->workingDir = sys_get_temp_dir() . '/composer_testdir';
-        $this->testFile = sys_get_temp_dir() . '/composer_test_file';
+        $this->workingDir = $this->getUniqueTmpDirectory();
+        $this->testFile = $this->getUniqueTmpDirectory() . '/composer_test_file';
     }
     }
 
 
     public function tearDown()
     public function tearDown()
@@ -54,7 +54,7 @@ class FilesystemTest extends TestCase
             $this->fs->removeDirectory($this->workingDir);
             $this->fs->removeDirectory($this->workingDir);
         }
         }
         if (is_file($this->testFile)) {
         if (is_file($this->testFile)) {
-            $this->fs->remove($this->testFile);
+            $this->fs->removeDirectory(dirname($this->testFile));
         }
         }
     }
     }
 
 

+ 18 - 1
tests/Composer/TestCase.php

@@ -56,12 +56,29 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
         return new AliasPackage($package, $normVersion, $version);
         return new AliasPackage($package, $normVersion, $version);
     }
     }
 
 
-    protected function ensureDirectoryExistsAndClear($directory)
+    protected static function getUniqueTmpDirectory()
+    {
+        $attempts = 5;
+        $root = sys_get_temp_dir();
+
+        do {
+            $unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-');
+            if (!file_exists($unique) && mkdir($unique, 0777)) {
+                return $unique;
+            }
+        } while (--$attempts);
+
+        throw new \RuntimeException('Failed to create a unique temporary directory.');
+    }
+
+    protected static function ensureDirectoryExistsAndClear($directory)
     {
     {
         $fs = new Filesystem();
         $fs = new Filesystem();
+
         if (is_dir($directory)) {
         if (is_dir($directory)) {
             $fs->removeDirectory($directory);
             $fs->removeDirectory($directory);
         }
         }
+
         mkdir($directory, 0777, true);
         mkdir($directory, 0777, true);
     }
     }
 }
 }