-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pickle now uses its own sandbox to download extensions' sources Closes #123
- Loading branch information
Showing
9 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Pickle; | ||
|
||
use Composer; | ||
|
||
class Config extends Composer\Config | ||
{ | ||
const DEFAULT_BASE_DIRNAME = '.pickle'; | ||
|
||
public function __construct($useEnvironment = true, $baseDir = null) | ||
{ | ||
if ($useEnvironment === true) { | ||
$baseDir = $baseDir ?: (getenv('PICKLE_BASE_DIR') ?: null); | ||
} | ||
|
||
$baseDir = $baseDir ?: (getenv('HOME') ?: sys_get_temp_dir()); | ||
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . self::DEFAULT_BASE_DIRNAME; | ||
|
||
parent::__construct($useEnvironment, $baseDir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Pickle\tests\units; | ||
|
||
use atoum; | ||
use Pickle\Config as TestedClass; | ||
|
||
class Config extends atoum | ||
{ | ||
public function test__construct() | ||
{ | ||
$this | ||
->given( | ||
$this->function->getenv = false, | ||
$this->function->sys_get_temp_dir = $tmpDir = 'tmp' | ||
) | ||
->when($this->newTestedInstance(false)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->never | ||
->when($this->newTestedInstance(true)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->once | ||
|
||
->given($this->function->getenv = function($var) use (& $baseDir) { return $var === 'PICKLE_BASE_DIR' ? $baseDir = uniqid() : false; }) | ||
->when($this->newTestedInstance(false)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->once | ||
->when($this->newTestedInstance(true)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->twice | ||
|
||
->given($this->function->getenv = function($var) use (& $baseDir, & $homeDir) { | ||
return $var === 'PICKLE_BASE_DIR' ? $baseDir = uniqid() : $homeDir = uniqid(); | ||
} | ||
) | ||
->when($this->newTestedInstance(false)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($homeDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->twice | ||
->when($this->newTestedInstance(true)) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice | ||
|
||
->when($this->newTestedInstance(false, $baseDir = uniqid())) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice | ||
|
||
->when($this->newTestedInstance(true, $baseDir = uniqid())) | ||
->then | ||
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir'])) | ||
->function('getenv') | ||
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice | ||
; | ||
} | ||
|
||
private function makePath($head, $tail) | ||
{ | ||
return $head . DIRECTORY_SEPARATOR . TestedClass::DEFAULT_BASE_DIRNAME . DIRECTORY_SEPARATOR . $tail; | ||
} | ||
} |