Пример #1
0
 /**
  * exec rsync from local dir to remote target dir
  * @param string $from local source path
  * @param string $to   remote target path
  *
  * @return string command return status
  */
 public function rsync($from, $to)
 {
     $user = $this->sshClient->getUser();
     $host = $this->sshClient->getHost();
     $dryFlag = $this->target->get('deploy.dry_run') ? '--dry-run' : '';
     $exclude = $this->rsyncExcludeFile ? '--exclude-from=' . $this->rsyncExcludeFile : '';
     $include = $this->rsyncIncludeFile ? '--include-from=' . $this->rsyncIncludeFile : '';
     $sshCmd = "-e 'ssh";
     $sshCmd .= $this->sshClient->getPort() ? " -p " . $this->sshClient->getPort() : "";
     $sshCmd .= "'";
     return $this->idx->local("rsync -rlpDvcz --delete {$sshCmd} {$dryFlag} {$exclude} {$include} {$from} {$user}@{$host}:{$to}");
 }
Пример #2
0
 public function getIdephixMock($targets, $targetName)
 {
     $this->output = fopen("php://memory", 'r+');
     $output = new StreamOutput($this->output);
     $currentTarget = new Config($targets[$targetName]);
     $sshClient = new SshClient(new FakeSsh2Proxy($this));
     $sshClient->setParameters($currentTarget->get('ssh_params'));
     $sshClient->setHost(current($currentTarget->get('hosts')));
     $sshClient->connect();
     $idx = $this->getMock('\\Idephix\\IdephixInterface');
     $idx->sshClient = $sshClient;
     $idx->output = $output;
     $idx->expects($this->any())->method('getCurrentTarget')->will($this->returnValue($currentTarget));
     $idx->expects($this->any())->method('getCurrentTargetName')->will($this->returnValue($targetName));
     $idx->expects($this->any())->method('local')->will($this->returnCallback(function ($cmd) use($output) {
         $output->writeln('Local: ' . $cmd);
     }));
     $idx->expects($this->any())->method('remote')->will($this->returnCallback(function ($cmd) use($output) {
         $output->writeln('Remote: ' . $cmd);
     }));
     return $idx;
 }
Пример #3
0
 public function testConnect()
 {
     $sshClient = new SshClient(new FakeSsh2Proxy($this));
     $sshClient->setParameters($this->params);
     $sshClient->setHost('localhost');
     $sshClient->connect();
     $this->assertEquals('text', $sshClient->exec('text'));
     $this->assertEquals('test out text', $sshClient->getLastOutput());
     $this->assertEquals('test err text', $sshClient->getLastError());
     $this->assertEquals('test', $sshClient->getUser());
     $this->assertEquals('23', $sshClient->getPort());
     $this->assertEquals('localhost', $sshClient->getHost());
     $sshClient->setHost('host');
     $this->assertEquals('host', $sshClient->getHost());
 }