Permalink
Browse files

added rsync extension

  • Loading branch information...
1 parent eb4b165 commit ac70915ce208a413e63585826f06876b85861953 @micheleorselli micheleorselli committed Mar 23, 2013
Showing with 100 additions and 14 deletions.
  1. +19 −14 composer.lock
  2. +43 −0 src/Idephix/Extension/Project/Project.php
  3. +38 −0 tests/Idephix/Extension/Project/ProjectTest.php
View
Oops, something went wrong.
@@ -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);
+ }
+}
@@ -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);
+ }
+
+}

0 comments on commit ac70915

Please sign in to comment.