Skip to content

Commit

Permalink
Merge eaf1db8 into fb6724d
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed May 6, 2020
2 parents fb6724d + eaf1db8 commit a254e81
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class_exists(__NAMESPACE__ . '\\' . $class);
$this->config = $composer->getConfig();
$this->package = $composer->getPackage();

$cacheDir = rtrim($this->config->get('cache-files-dir'), '\/');

// disable when cache is not usable
if (preg_match('{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}', $cacheDir)) {
return $this->disable();
}

if (array_key_exists('argv', $GLOBALS)) {
if (in_array('help', $GLOBALS['argv'])) {
return $this->disable();
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ public function testOnPostDependenciesSolving()
$plugin->onPostDependenciesSolving($evp->reveal());
}

/**
* @dataProvider nullCacheDataProvider
*/
public function testDisabledWhenCacheIsOff($cacheDir)
{
$plugin = new Plugin;
$this->configp->get('cache-files-dir')
->willReturn($cacheDir);

$plugin->activate($this->composerp->reveal(), $this->iop->reveal());

$this->assertTrue($plugin->isDisabled());
}

public function nullCacheDataProvider()
{
return array(
array('$null'),
array('nul'),
array('NUL'),
array('/dev/null'),
);
}

private function createDummyOperations()
{
return array(
Expand Down

0 comments on commit a254e81

Please sign in to comment.