Merge pull request #528 from x3ro/download-env-fixes

Fix environment variable replacement in "download" function
This commit is contained in:
Anton Medvedev 2016-01-15 13:48:28 +07:00
commit ec54f4ce32
2 changed files with 36 additions and 3 deletions

View File

@ -386,6 +386,9 @@ function upload($local, $remote)
function download($local, $remote)
{
$server = Context::get()->getServer();
$local = env()->parse($local);
$remote = env()->parse($remote);
$server->download($local, $remote);
}

View File

@ -50,7 +50,10 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
$this->_input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$this->_output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$this->_server = $this->getMockBuilder('Deployer\Server\ServerInterface')->disableOriginalConstructor()->getMock();
$this->_env = new Environment();
$this->_env->set("local_path", __DIR__ . '/../fixture/app');
$this->_env->set("remote_path", "/home/www");
$this->deployer = new Deployer($this->console, $this->_input, $this->_output);
Context::push(new Context($this->_server, $this->_env, $this->_input, $this->_output));
@ -149,7 +152,7 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
public function testUpload()
{
$this->_server
->expects($this->any())
->expects($this->atLeastOnce())
->method('upload')
->with(
$this->callback(function ($local) {
@ -160,9 +163,36 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
}));
// Directory
upload(__DIR__ . '/../fixture/app', '/home/www');
upload('{{local_path}}', '{{remote_path}}');
// File
upload(__DIR__ . '/../fixture/app/README.md', '/home/www/README.md');
upload('{{local_path}}/README.md', '{{remote_path}}/README.md');
}
public function testDownloadFile()
{
$this->_server
->expects($this->once())
->method('download')
->with(
$this->_env->get("local_path") . "/README.md",
$this->_env->get("remote_path") . "/README.md"
);
download('{{local_path}}/README.md', '{{remote_path}}/README.md');
}
public function testDownloadDirectory()
{
$this->_server
->expects($this->once())
->method('download')
->with(
$this->_env->get("local_path"),
$this->_env->get("remote_path")
);
download('{{local_path}}', '{{remote_path}}');
}
}