Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added rsync extension #2

Merged
merged 1 commit into from Mar 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions src/Idephix/Extension/Project/Project.php
@@ -0,0 +1,43 @@
<?php

namespace Idephix\Extension\Project;

use Idephix\Idephix;
use Idephix\Extension\IdephixAwareInterface;

/**
* @todo:
* - allow for $exclude to be an array
* - manage ports different from the default one
* - check to undefined params in currentTarget
*/
class Project implements IdephixAwareInterface
{
private $idx;

public function setIdephix(Idephix $idx)
{
$this->idx = $idx;
}

public function rsyncProject($remote_dir, $local_dir = null, $exclude = null, $extra_opts = null, $ssh_opts = null)
{
if (substr($remote_dir, -1) != '/')
{
$remote_dir .= '/';
}

$target = $this->idx->getCurrentTarget();
$user = $target['ssh_params']['user'];
$host = $this->idx->getCurrentTargetHost();

if (file_exists($exclude))
{
$extra_opts .= ' --exclude-from='.$exclude;
}

$cmd = "rsync -rlDcz --force --delete --progress $extra_opts -e 'ssh' ./ $user@$host:$remote_dir";

return $this->idx->local($cmd);
}
}
38 changes: 38 additions & 0 deletions tests/Idephix/Extension/Project/ProjectTest.php
@@ -0,0 +1,38 @@
<?php
namespace Idephix\Extension\Project;

use Idephix\Extension\Project\Project;

class ProjectTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->idx = $this->getMockBuilder('Idephix\Idephix')
->disableOriginalConstructor()
->getMock();

$this->idx->expects($this->exactly(1))
->method('local')
->will($this->returnArgument(0));

$this->idx->expects($this->exactly(1))
->method('getCurrentTarget')
->will($this->returnValue(array('ssh_params' => array('user' => 'kea'))));

$this->idx->expects($this->exactly(1))
->method('getCurrentTargetHost')
->will($this->returnValue('banana.com'));

$this->project = new Project();
$this->project->setIdephix($this->idx);

}

public function testRsyncProject()
{
$result = $this->project->rsyncProject('/a/remote');

$this->assertEquals("rsync -rlDcz --force --delete --progress -e 'ssh' ./ kea@banana.com:/a/remote/", $result);
}

}