public function testPipeAsArgument2() { $otp = 'foobar'; $cmd1 = new Command(); $cmd1->setCommand('php')->addArgument(new Argument(__DIR__ . "/cmd.php"))->addArgument(new Argument('--otp', $otp)); $cmd2 = new Command(); $cmd2->setCommand('php')->addArgument(new Argument(__DIR__ . "/cmd.php"))->addArgument(new Argument(PIPE_PH)); $result = $cmd1->chain()->add($cmd2, null, true)->run(); $res = json_decode($result[1]->getStdOut()); self::assertEquals($otp, $res->Args[1]); }
/** * @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); }