当前位置: 首页>>代码示例>>PHP>>正文


PHP Command::removeOption方法代码示例

本文整理汇总了PHP中Command::removeOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::removeOption方法的具体用法?PHP Command::removeOption怎么用?PHP Command::removeOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Command的用法示例。


在下文中一共展示了Command::removeOption方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCommandClass

 public function testCommandClass()
 {
     $commandLine = "echo \"Hello world!\"";
     $c = new Command($commandLine);
     $this->assertEquals($commandLine, $c);
     $stdOut = "./stdout.log";
     $c->setStdOut($stdOut);
     $this->assertEquals($stdOut, $c->getStdOut(), "stdout setter and getter are ok.");
     $stdErr = "./stderr.log";
     $c->setStdErr($stdErr);
     $this->assertEquals($stdErr, $c->getStdErr(), "stderr setter and getter are ok.");
     $c = new Command($commandLine);
     $c->runInBackground();
     if (substr(php_uname(), 0, 7) == "Windows") {
         $stdOutNul = ">NUL";
         $stdErrNul = "2>NUL";
     } else {
         $stdOutNul = "/dev/null";
         $stdErrNul = "2>/dev/null";
     }
     $this->assertEquals($stdOutNul, $c->getStdOut(), "If stdout is not set set it to {$stdOutNul} when running in background.");
     $this->assertEquals($stdErrNul, $c->getStdErr(), "If stderr is not set set it to {$stdErrNul} when running in background.");
     $c = new Command($commandLine);
     $c->setStdErr($stdErr);
     $c->setStdOut($stdOut);
     $c->runInBackground();
     $this->assertEquals($stdOut, $c->getStdOut(), "If stdout is set don't overwrite it when running in background.");
     $this->assertEquals($stdErr, $c->getStdErr(), "If stderr is set don't overwrite it when running in background.");
     $arg1 = "arg1";
     $arg2 = "arg2";
     $arg3 = "arg3";
     $c->addArgument($arg1);
     $c->addArgument($arg3);
     $expectedLine = "{$commandLine} {$arg1} {$arg3}";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends arguments.");
     $c->addArgument($arg2, 2);
     $expectedLine = "{$commandLine} {$arg1} {$arg2} {$arg3}";
     $this->assertEquals($expectedLine, (string) $c, "Command properly insertets arguments at given position.");
     $arg2_1 = "arg2_1";
     $c->addArgument($arg2_1, 2, true);
     $expectedLine = "{$commandLine} {$arg1} {$arg2_1} {$arg3}";
     $this->assertEquals($expectedLine, (string) $c, "Command properly replaces arguments.");
     $c = new Command($commandLine);
     $c->addArgument($arg3, 3);
     $c->addArgument($arg1, 1);
     $c->addArgument($arg2, 2);
     $expectedLine = "{$commandLine} {$arg1} {$arg2} {$arg3}";
     $this->assertEquals($expectedLine, (string) $c, "Command properly insertets arguments added in mixed order.");
     $c = new Command($commandLine);
     $c->addOption("-c");
     $expectedLine = "{$commandLine} -c";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends no-value option.");
     $c->removeOption("-c");
     $this->assertEquals($commandLine, (string) $c, "Command properly removesg options.");
     $c->addOption("-c:", "value_c");
     $expectedLine = "{$commandLine} -c \"value_c\"";
     $this->assertEquals($expectedLine, (string) $c, "Commadn properly appends options with required value.");
     $c = new Command($commandLine);
     $c->addOption("-c::");
     $expectedLine = "{$commandLine} -c";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends optional value option without value set.");
     $c = new Command($commandLine);
     $c->addOption("-c::", "value_c");
     $expectedLine = "{$commandLine} -c=\"value_c\"";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends optional value option.");
     $c = new Command($commandLine);
     $c->addOption("-c", "value_c");
     $expectedLine = "{$commandLine} -c";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends no-value option without value even if value is set.");
     $c = new Command($commandLine);
     $c->addOption("-a");
     $c->addOption("-b");
     $expectedLine = "{$commandLine} -a -b";
     $this->assertEquals($expectedLine, (string) $c, "Command properly appends multiple options");
 }
开发者ID:chaos-drone,项目名称:exec,代码行数:75,代码来源:CommandTest.php


注:本文中的Command::removeOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。