From f829a160fb2197cfde52a95ab89cf8515b101d90 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 26 Jan 2016 14:32:04 +0100 Subject: [PATCH] use a proper tmp directory this test failed on OSX before, trying to create a directory at the root of the filesystem --- src/Composer/Command/CreateProjectCommand.php | 2 +- .../Test/Repository/RepositoryManagerTest.php | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 4ddc2cfa7..ace946f3a 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -294,7 +294,7 @@ EOT // handler Ctrl+C for unix-like systems if (function_exists('pcntl_signal')) { - declare (ticks = 100); + declare(ticks=100); pcntl_signal(SIGINT, function () use ($directory) { $fs = new Filesystem(); $fs->removeDirectory($directory); diff --git a/tests/Composer/Test/Repository/RepositoryManagerTest.php b/tests/Composer/Test/Repository/RepositoryManagerTest.php index 4293dff66..0a419be6c 100644 --- a/tests/Composer/Test/Repository/RepositoryManagerTest.php +++ b/tests/Composer/Test/Repository/RepositoryManagerTest.php @@ -13,22 +13,49 @@ namespace Composer\Repository; use Composer\TestCase; +use Composer\Util\Filesystem; class RepositoryManagerTest extends TestCase { + protected $tmpdir; + + public function setUp() + { + $this->tmpdir = $this->getUniqueTmpDirectory(); + } + + public function tearDown() + { + if (is_dir($this->tmpdir)) { + $fs = new Filesystem(); + $fs->removeDirectory($this->tmpdir); + } + } + /** * @dataProvider creationCases */ - public function testRepoCreation($type, $config, $exception = null) + public function testRepoCreation($type, $options, $exception = null) { if ($exception) { $this->setExpectedException($exception); } + $rm = new RepositoryManager( $this->getMock('Composer\IO\IOInterface'), - $this->getMock('Composer\Config'), + $config = $this->getMock('Composer\Config', array('get')), $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock() ); + + $tmpdir = $this->tmpdir; + $config + ->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($arg) use ($tmpdir) { + return 'cache-repo-dir' === $arg ? $tmpdir : null; + })) + ; + $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository'); $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository'); $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository'); @@ -40,7 +67,7 @@ class RepositoryManagerTest extends TestCase $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository'); $rm->createRepository('composer', array('url' => 'http://example.org')); - $rm->createRepository($type, $config); + $rm->createRepository($type, $options); } public function creationCases()