Esempio n. 1
0
 /**
  * @return array
  */
 public function supportsCurrentOS(Detector $detector = null)
 {
     if ($detector === null) {
         $detector = new Detector();
     }
     return $detector->isUnixLike();
 }
Esempio n. 2
0
 /**
  * @covers \Tivie\Command\Command::chdir
  * @covers \Tivie\Command\Command::setCurrentWorkingDirectory
  * @covers \Tivie\Command\Command::exec
  * @covers \Tivie\Command\Command::proc_open
  */
 public function testChdir()
 {
     $s = DIRECTORY_SEPARATOR;
     $dir = realpath(__DIR__ . $s . ".." . $s . "dir" . $s . "test" . $s);
     if (!$dir) {
         // something went wrong setting the relative path so we inform and quick gracefully
         fwrite(STDERR, "CommandTest::testChdir() - Failed to discover the test directory in testChdir so the " . "test was skipped");
         return;
     }
     $cmd = new Command();
     if ($this->os->isWindowsLike()) {
         $cmd->setCommand('cd');
     } else {
         $cmd->setCommand('pwd');
     }
     // Test with no working directory
     $result = $this->getResultMock();
     $result->expects($this->once())->method('setStdOut')->with($this->equalTo(realpath(getcwd())));
     $cmd->run($result);
     // Test with working directory
     $cmd->setCurrentWorkingDirectory($dir);
     //Test with exec
     $cmd->setFlags(FORCE_USE_EXEC);
     $result = $this->getResultMock();
     $result->expects($this->once())->method('setStdOut')->with($this->equalTo($dir));
     $cmd->run($result);
     //Test with proc_open
     $cmd->setFlags(FORCE_USE_PROC_OPEN);
     $result = $this->getResultMock();
     $result->expects($this->once())->method('setStdOut')->with($this->equalTo($dir));
     $cmd->run($result);
 }
Esempio n. 3
0
 public function testWithPingCommand()
 {
     $osDetect = new Detector();
     $cmd1 = new Command(ESCAPE);
     $cmd1->setCommand('ping')->addArgument(new Argument('-n', 1, \Tivie\OS\WINDOWS_FAMILY))->addArgument(new Argument('-l', 32, \Tivie\OS\WINDOWS_FAMILY))->addArgument(new Argument('-c', 1, \Tivie\OS\UNIX_FAMILY))->addArgument(new Argument('-s', 24, \Tivie\OS\UNIX_FAMILY))->addArgument(new Argument('www.google.com'));
     if ($osDetect->isWindowsLike()) {
         $cmdStr = 'ping -"n" "1" -"l" "32" "www.google.com"';
     } else {
         $cmdStr = "ping -'c' '1' -'s' '24' 'www.google.com'";
     }
     self::assertEquals($cmdStr, $cmd1->getBuiltCommand());
     $cmd2 = new Command();
     $cmd2->setCommand('php')->addArgument(new Argument(__DIR__ . "/cmd.php"))->addArgument(new Argument('--hasStdIn'));
     $results = $cmd1->chain()->add($cmd2, RUN_REGARDLESS, true)->run();
     $res = json_decode($results[1]->getStdOut());
     self::assertEquals(2, $res->NumOfArgs);
     self::assertEquals(trim($results[0]->getStdOut()), $results[1]->getStdIn());
 }
Esempio n. 4
0
 /**
  * Find the right command to launch a url on a platform.
  * @param string $url
  * @return string
  */
 protected function getBrowserCommand($url)
 {
     // Mac
     if (\Tivie\OS\MACOSX == $this->os->getType()) {
         return "open {$url}";
     }
     // Windows
     if ($this->os->isWindowsLike()) {
         return "start {$url}";
     }
     // everything else (most likely unix)
     return "xdg-open {$url}";
 }
Esempio n. 5
0
 private function escapeshellarg($arg)
 {
     //remove whitespaces
     $arg = trim($arg);
     // remove " from the beginning and end
     $arg = trim($arg, '"');
     if ($this->os->isWindowsLike()) {
         // escape " by doubling
         $arg = str_replace('"', '""', $arg);
         // check variable expansion
         $this->checkWindowsEnvVar($arg);
         $arg = "\"{$arg}\"";
     } else {
         $arg = escapeshellarg($arg);
     }
     return $arg;
 }
 /**
  * @param Detector|null $detector
  * @return string
  * @throws \Exception
  */
 public static function getProcessForCurrentOS(Detector $detector = null)
 {
     if ($detector === null) {
         $detector = new Detector();
     }
     if ($detector->isUnixLike()) {
         return 'php ' . __DIR__ . DIRECTORY_SEPARATOR . 'child-process.php';
     }
     if ($detector->isWindowsLike()) {
         return 'php.exe ' . __DIR__ . DIRECTORY_SEPARATOR . 'child-process.php';
     }
     throw new \Exception('Unknown OS family');
 }