예제 #1
0
파일: RealTest.php 프로젝트: tivie/command
 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());
 }
예제 #2
0
 /**
  * @covers \Tivie\Command\Command::addArgument
  * @covers \Tivie\Command\Command::setCommand
  * @covers \Tivie\Command\Command::getBuiltCommand
  * @covers \Tivie\Command\Command::__toString()
  */
 public function testGetBuiltCommand()
 {
     $cmd = new Command(null, $this->os);
     $a1K = 'bar';
     $a1V = 'barVal';
     $a2K = 'baz';
     $a2V = array('bazval1', 'bazval2');
     $cmd->setCommand('foo')->addArgument(new Argument($a1K, $a1V))->addArgument(new Argument($a2K, $a2V));
     $expCmd = "foo {$a1K} {$a1V} {$a2K} {$a2V['0']} {$a2K} {$a2V['1']}";
     self::assertEquals($expCmd, $cmd->getBuiltCommand());
 }