diff --git a/src/Composer/Cache.php b/src/Composer/Cache.php
index 3dbb06eed..c3cba603a 100644
--- a/src/Composer/Cache.php
+++ b/src/Composer/Cache.php
@@ -175,6 +175,15 @@ class Cache
return false;
}
+ public function clear()
+ {
+ if ($this->enabled) {
+ return $this->filesystem->removeDirectory($this->root);
+ }
+
+ return false;
+ }
+
public function gc($ttl, $maxSize)
{
if ($this->enabled) {
diff --git a/src/Composer/Command/ClearCacheCommand.php b/src/Composer/Command/ClearCacheCommand.php
index 7ab17806d..362d28500 100644
--- a/src/Composer/Command/ClearCacheCommand.php
+++ b/src/Composer/Command/ClearCacheCommand.php
@@ -42,10 +42,10 @@ EOT
$io = $this->getIO();
$cachePaths = array(
- 'cache-dir' => $config->get('cache-dir'),
- 'cache-files-dir' => $config->get('cache-files-dir'),
- 'cache-repo-dir' => $config->get('cache-repo-dir'),
'cache-vcs-dir' => $config->get('cache-vcs-dir'),
+ 'cache-repo-dir' => $config->get('cache-repo-dir'),
+ 'cache-files-dir' => $config->get('cache-files-dir'),
+ 'cache-dir' => $config->get('cache-dir'),
);
foreach ($cachePaths as $key => $cachePath) {
@@ -63,7 +63,7 @@ EOT
}
$io->writeError("Clearing cache ($key): $cachePath");
- $cache->gc(0, 0);
+ $cache->clear();
}
$io->writeError('All caches cleared.');
diff --git a/tests/Composer/Test/CacheTest.php b/tests/Composer/Test/CacheTest.php
index 4fb467d22..c379438a9 100644
--- a/tests/Composer/Test/CacheTest.php
+++ b/tests/Composer/Test/CacheTest.php
@@ -107,4 +107,18 @@ class CacheTest extends TestCase
}
$this->assertFileExists("{$this->root}/cached.file3.zip");
}
+
+ public function testClearCache()
+ {
+ $this->finder
+ ->method('removeDirectory')
+ ->with($this->root)
+ ->willReturn(true);
+
+ $this->assertTrue($this->cache->clear());
+
+ for ($i = 0; $i < 3; $i++) {
+ $this->assertFileNotExists("{$this->root}/cached.file{$i}.zip");
+ }
+ }
}