Beispiel #1
0
 public function testGetSessionResourceWillCallSessionGetResource()
 {
     $session = $this->getMock('Ssh\\Session', array('getResource'), array(), '', false);
     $session->expects($this->once())->method('getResource')->will($this->returnValue('aResource'));
     $exec = new Exec($session);
     $this->assertEquals('aResource', $exec->getSessionResource());
 }
Beispiel #2
0
 public function execute()
 {
     if (!isset($this->options['executable'])) {
         $this->error('Tester executable is not defined.');
     }
     $cmd = '';
     $cmd .= escapeshellarg($this->options['executable']) . ' ';
     $cmd .= '-s ';
     // show skipped tests
     $cmd .= escapeshellarg($this->target) . ' ';
     $optionalSwitches = ['iniFile' => '-c', 'interpreter' => '-p', 'threads' => '-j', 'mode' => '-o'];
     foreach ($optionalSwitches as $name => $switch) {
         if (isset($this->options[$name])) {
             $cmd .= $switch . ' ';
             $cmd .= escapeshellarg($this->options[$name]) . ' ';
         }
     }
     $currdir = getcwd();
     $result = @chdir($this->workingDir);
     if (!$result) {
         $this->error("Cannot change working directory to '{$this->workingDir}'.");
     }
     $command = new Exec();
     $command->setCommand($cmd);
     $result = $command->execute();
     if ($result->getResult() !== 0) {
         $this->error(sprintf('Tests failed with code %d.', $result->getResult()));
     }
     $result = @chdir($currdir);
     if (!$result) {
         $this->error("Cannot change working directory back to '{$currdir}'.");
     }
 }
Beispiel #3
0
 public function testExecutingCommandInBackground()
 {
     $script_sleep = realpath(__DIR__) . '/../data/sleep.php';
     $commandSleep = new Command("php {$script_sleep}");
     $exec = new Exec();
     $startTime = microtime(true);
     $exec->run($commandSleep);
     $this->assertGreaterThanOrEqual(1, microtime(true) - $startTime, "Script execution took 1 second");
     $commandSleep->runInBackground(true);
     $startTime = microtime(true);
     $exec->run($commandSleep);
     $this->assertLessThan(1, microtime(true) - $startTime, "Script that takes at least 1 secon is run in background");
 }
Beispiel #4
0
 /**
  * hasBinary returns true if the binary is available in any of the PATHs.
  *
  * @param string $binaryName
  *
  * @return bool
  */
 public static function hasBinary($binaryName)
 {
     $exec = Exec::create();
     if (self::isWindows()) {
         // 'where.exe' uses 0 for success, 1 for failure to find
         $exec->run('where.exe', '/q', $binaryName);
         return $exec->getStatus() === 0;
     }
     // 'which' uses 0 for success, 1 for failure to find
     $exec->run('which', $binaryName);
     if ($exec->getStatus() === 0) {
         return true;
     }
     // 'whereis' does not use status codes. Check for a matching line instead.
     $exec->run('whereis', '-b', $binaryName);
     foreach ($exec->getOutput() as $line) {
         if (preg_match('/^' . preg_quote($binaryName) . ': .*$/', $line) === 1) {
             return true;
         }
     }
     return false;
 }
Beispiel #5
0
 /**
  * deleteContents of a folder recursively, but not the folder itself.
  *
  * On Windows systems this will try to remove the read-only attribute if needed.
  *
  * @param string $path Path of folder whose contents will be deleted
  *
  * @throws \RuntimeException Thrown when something could not be deleted.
  */
 public static function deleteContents($path)
 {
     if (!is_dir($path)) {
         return;
     }
     /** @var \SplFileInfo[] $files */
     $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($files as $fileInfo) {
         if ($fileInfo->isDir()) {
             if (@rmdir($fileInfo->getRealPath()) === false) {
                 throw new \RuntimeException(sprintf("Unable to delete child folder '%s' in '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
             }
         } elseif (@unlink($fileInfo->getRealPath()) === false) {
             if (OS::isWindows()) {
                 Exec::create('attrib', '-R', $fileInfo->getRealPath())->run();
                 if (@unlink($fileInfo->getPathname())) {
                     continue;
                 }
             }
             throw new \RuntimeException(sprintf("Unable to delete file '%s' in folder '%s': %s", $fileInfo->getFilename(), $fileInfo->getPathname(), error_get_last()['message']));
         }
     }
 }
Beispiel #6
0
 public function execute()
 {
     parent::execute();
     return $this->conn->getLastId();
 }
Beispiel #7
0
 public function execute()
 {
     if (!isset($this->options['executable'])) {
         $this->error('PHPUnit executable not defined.');
     }
     $cmd = '';
     if (isset($this->options['xdebugExtensionFile'])) {
         if (!is_file($this->options['xdebugExtensionFile'])) {
             // PHP is quite when extension file does not exists
             $this->error("Xdebug extension file '{$this->options['xdebugExtensionFile']}' does not exists.");
         }
         $cmd .= 'php -d zend_extension=' . escapeshellarg($this->options['xdebugExtensionFile']) . ' ';
     }
     $cmd .= escapeshellarg($this->options['executable']) . ' ';
     $cmd .= escapeshellarg($this->target) . ' ';
     $options = ['configFile' => '--configuration'];
     foreach ($options as $name => $switch) {
         if (isset($this->options[$name])) {
             $cmd .= $switch . ' ';
             $cmd .= escapeshellarg($this->options[$name]) . ' ';
         }
     }
     $currdir = getcwd();
     $result = @chdir($this->workingDir);
     if (!$result) {
         $this->error("Cannot change working directory to '{$this->workingDir}'.");
     }
     $command = new Exec();
     $command->setCommand($cmd);
     $result = $command->execute();
     if ($result->getResult() !== 0) {
         $this->error(sprintf('Tests failed with code %d.', $result->getResult()));
     }
     $result = @chdir($currdir);
     if (!$result) {
         $this->error("Cannot change working directory back to '{$currdir}'.");
     }
 }
Beispiel #8
0
 /**
  * get current working directory
  */
 public static function getCwd()
 {
     if (!Exec::allowed() || OperatingSystem::isWindows()) {
         return getcwd();
     }
     Exec::run('pwd', $folder);
     return $folder;
 }
Beispiel #9
0
 /**
  * Store the confluence document in the confluence wiki.
  *
  * @param string $newDoc New document in confluence markup
  *
  * @return void
  */
 public function storePage($newDoc)
 {
     //we cannot pipe because of
     //  https://studio.plugins.atlassian.com/browse/CSOAP-121
     $tmpfile = tempnam(sys_get_temp_dir(), 'deploy-confluence-');
     file_put_contents($tmpfile, $newDoc);
     $cmd = sprintf($this->cmd['cflcli'] . ' --server %s --user %s --password %s' . ' --action storePage --space %s --title %s --file %s --quiet', escapeshellarg($this->cflHost), escapeshellarg($this->cflUser), escapeshellarg($this->cflPass), escapeshellarg($this->cflSpace), escapeshellarg($this->cflPage), escapeshellarg($tmpfile));
     list($lastline, $retval) = Exec::run($cmd);
     unlink($tmpfile);
     if ($retval !== 0) {
         throw new Exception('Error storing new document in confluence' . "\n" . $lastline, 30);
     }
 }
Beispiel #10
0
 /**
  * @return null|string
  */
 private function readMercurial()
 {
     $hgDir = Path::combine($this->repositoryRoot, '.hg');
     if (!is_dir($hgDir) || !OS::hasBinary('hg')) {
         return null;
     }
     $hg = Exec::create('hg', '--repository', $this->repositoryRoot);
     // Removes everything but the tag if distance is zero.
     $hg->run('log', '-r', '.', '--template', '{latesttag}{sub(\'^-0-m.*\', \'\', \'-{latesttagdistance}-m{node|short}\')}');
     $tag = Dot::get($hg->getOutput(), 0);
     // Actual null if no lines were returned or `hg log` returned actual "null".
     // Either way, need to fall back to the revision id.
     if ($tag === null || $tag === 'null' || Strings::startsWith($tag, 'null-')) {
         $hg->run('id', '-i');
         $tag = Dot::get($hg->getOutput(), 0);
         // Remove 'dirty' plus from revision id
         $tag = rtrim($tag, '+');
     }
     $summary = $hg->run('summary')->getOutput();
     $isDirty = 0 === count(array_filter($summary, function ($line) {
         return preg_match('/^commit: .*\\(clean\\)$/', $line) === 1;
     }));
     if ($isDirty) {
         $tag .= '-dirty';
     }
     return $tag;
 }