diff --git a/src/Downloader.php b/src/Downloader.php index 0d798a25..fd43803c 100644 --- a/src/Downloader.php +++ b/src/Downloader.php @@ -26,7 +26,16 @@ public function __construct(Composer $composer, IOInterface $io, array $disabled $this->io = $io; $this->disabledDownloaders = $disabledDownloaders; - $this->cacheDir = $composer->getConfig()->get('cache-dir') . '/patches'; + // If --no-cache is passed to Composer, we need a different location to + // download patches to. When --no-cache is passed, $composer_cache is + // set to /dev/null. + $composer_cache = $composer->getConfig()->get('cache-dir'); + if (!is_dir($composer_cache)) { + $composer_cache = sys_get_temp_dir(); + } + + // If the cache directory doesn't exist, create it. + $this->cacheDir = $composer_cache . '/patches'; if (!is_dir($this->cacheDir)) { mkdir($this->cacheDir); } diff --git a/tests/_data/fixtures/apply-git-patch-from-web-no-cache/composer.json b/tests/_data/fixtures/apply-git-patch-from-web-no-cache/composer.json new file mode 100644 index 00000000..f598ea55 --- /dev/null +++ b/tests/_data/fixtures/apply-git-patch-from-web-no-cache/composer.json @@ -0,0 +1,29 @@ +{ + "name": "cweagans/composer-patches-test-project", + "description": "Project for use in cweagans/composer-patches acceptance tests.", + "type": "project", + "license": "BSD-3-Clause", + "repositories": [ + { + "type": "path", + "url": "../../../../" + } + ], + "require": { + "cweagans/composer-patches": "*@dev", + "cweagans/composer-patches-testrepo": "~1.0" + }, + "extra": { + "patches": { + "cweagans/composer-patches-testrepo": { + "Add a file": "https://patch-diff.githubusercontent.com/raw/cweagans/composer-patches-testrepo/pull/1.patch" + } + } + }, + "config": { + "preferred-install": "source", + "allow-plugins": { + "cweagans/composer-patches": true + } + } +} diff --git a/tests/acceptance/ApplyGitPatchFromWebNoCacheCept.php b/tests/acceptance/ApplyGitPatchFromWebNoCacheCept.php new file mode 100644 index 00000000..27a26c79 --- /dev/null +++ b/tests/acceptance/ApplyGitPatchFromWebNoCacheCept.php @@ -0,0 +1,13 @@ +wantTo('modify a package using a patch downloaded from the internet (with "composer --no-cache")'); +$I->amInPath(codecept_data_dir('fixtures/apply-git-patch-from-web-no-cache')); +$I->runComposerCommand('install', ['-vvv', '--no-cache']); +$I->canSeeFileFound('./vendor/cweagans/composer-patches-testrepo/src/OneMoreTest.php');