public function run($commandHandlerString)
 {
     $commandHandler = new $commandHandlerString();
     if ($commandHandler->preExec()) {
         $result = $this->shellExecService->shellExec($commandHandler->getCommand());
         $commandHandler->postExec($result->isOk());
         return $result->isOk();
     }
     return false;
 }
 public function testGetPublicSshKeyFromPrivateKeyOk()
 {
     $keyFileName = __DIR__ . '/../resource/private_key.txt';
     $this->shellExecServiceMock->expects($this->at(0))->method('shellExec')->with($this->equalTo('which ssh-keygen'))->will($this->returnValue(new ShellExecResult(0, array())));
     $this->configServiceMock->expects($this->once())->method('getPrivateKeyFilename')->will($this->returnValue($keyFileName));
     $this->shellExecServiceMock->expects($this->at(1))->method('shellExec')->with($this->equalTo("ssh-keygen -P '' -q -y -f '{$keyFileName}'"))->will($this->returnValue(new ShellExecResult(0, array('ssh-rsa AAAAB'))));
     $publicKey = $this->cut->getPublicSshKeyFromPrivateKey();
     $this->assertEquals('ssh-rsa AAAAB', $publicKey);
 }
 public function getPublicSshKeyFromPrivateKey()
 {
     if (!$this->isSshKeygenPresent()) {
         return null;
     }
     $keyFilename = $this->configService->getPrivateKeyFilename();
     if (!file_exists($keyFilename)) {
         return null;
     }
     $result = $this->shellExecService->shellExec("ssh-keygen -P '' -q -y -f '{$keyFilename}'");
     if (!$result->isOk()) {
         return null;
     }
     $output = $result->getOutput();
     return $output[0];
 }
 public function testRunFailureCallback()
 {
     TestCommandHandlerFailure::$test = 1;
     $retVal = $this->cut->run('OCA\\EasyBackup\\TestCommandHandlerFailure');
     $this->assertEquals(false, TestCommandHandlerFailure::$test);
 }