Пример #1
0
 public function mock_doRun()
 {
     $this->Arguments = func_get_args();
     $this->Input->readline(1024);
     $this->Output->write('foo', IOutput::STDOUT);
     $this->Output->write('foo', IOutput::STDERR);
     return -1;
 }
Пример #2
0
 /**
  * @depends test_isSystemCallInterupt
  * @covers ::transferStreams
  * @covers ::_transferStdIn
  * @covers ::_transferStdOut
  * @covers ::_transferStdErr
  * @covers ::getStatus
  */
 public function test_transferStreams()
 {
     $Input = tempnam(sys_get_temp_dir(), 'input');
     $Pipes = array(Command::STDIN => fopen($Input, 'w'), Command::STDOUT => fopen('data:text/plain,test output', 'r'), Command::STDERR => fopen('data:text/plain,test error', 'r'));
     $Property = new ReflectionProperty($this->Command, '_Pipes');
     $Property->setAccessible(true);
     $Property->setValue($this->Command, $Pipes);
     $this->Input->setMediator($this->Mediator);
     $this->Output->setMediator($this->Mediator);
     $this->Command->transferStreams($this->Input, $this->Output, 10);
     $this->assertEquals('test output', $this->Output->stdOut->getContents(), 'ShellCommand::_transferStreams() Failed to transfer STDOUT');
     $this->assertEquals('test error', $this->Output->stdErr->getContents(), 'ShellCommand::_transferStreams() Failed to transfer STDERR');
     $this->assertEquals($this->Input->stdIn->getContents(), file_get_contents($Input), 'ShellCommand::_transferStreams() Failed to trasfer STDIN');
     foreach ($Pipes as $fp) {
         fclose($fp);
     }
     sleep(1);
     @unlink($Input);
 }
Пример #3
0
 /**
  * Runs the command.
  *
  * @param \BLW\Type\Command\IInput $Input
  *            Input object to read data from.
  * @param \BLW\Type\Command\IOutput $Output
  *            Output object to write data to.
  * @param integer $flags
  *            Run flags.
  * @return mixed Result of command.
  */
 public function run(IInput $Input, IOutput $Output, $flags = ICommand::RUN_FLAGS)
 {
     // Is mediator set?
     if (($Mediator = $this->getMediator()) instanceof IMediator) {
         // Update Input
         $Input->setMediator($Mediator);
         $Input->setMediatorID($this->getMediatorID());
         // Update Output
         $Output->setMediator($Mediator);
         $Output->setMediatorID($this->getMediatorID());
     }
     // Perform pre run
     $this->doNotify(ICommand::RUN, array('flags' => &$flags));
     // Evaluate flags
     // .....
     // Perform run
     $start = new DateTime();
     $return = $this->doRun($Input, $Output);
     // Perform post run
     $this->doNotify(ICommand::SHUTDOWN, array('Result' => &$return, 'Start' => &$start));
     // Reset Input
     $Input->clearMediator();
     $Input->setMediatorID('*');
     // Reset Output
     $Output->clearMediator();
     $Output->setMediatorID('*');
     // Done
     return $return;
 }