Example #1
0
    public function testRunError()
    {
        $this->_process->getCommandLine()->willReturn('svn log')->shouldBeCalled();
        $process = $this->_process;
        $this->_process->mustRun(null)->will(function () use($process) {
            $mock_definition = array('isSuccessful' => false, 'getExitCode' => 1, 'getExitCodeText' => 'exit code text', 'isOutputDisabled' => false, 'getOutput' => 'normal output', 'getErrorOutput' => 'error output');
            foreach ($mock_definition as $method_name => $return_value) {
                $process->{$method_name}()->willReturn($return_value)->shouldBeCalled();
            }
            throw new ProcessFailedException($process->reveal());
        })->shouldBeCalled();
        $this->_process->getOutput()->shouldNotBeCalled();
        $this->_io->isVerbose()->shouldNotBeCalled();
        $this->_io->isDebug()->shouldNotBeCalled();
        $this->_cacheManager->getCache(Argument::any())->shouldNotBeCalled();
        $thrown_exception = null;
        try {
            $this->_command->run();
        } catch (\Exception $thrown_exception) {
            $this->assertEquals('ConsoleHelpers\\SVNBuddy\\Exception\\RepositoryCommandException', get_class($thrown_exception), 'Exception of correct class was thrown');
        }
        $this->assertNotNull($thrown_exception, 'Exception was thrown when command execution failed');
        $error_msg = <<<MSG
Command:
svn log
Error #0:
error output
MSG;
        $this->assertEquals($error_msg, $thrown_exception->getMessage());
    }
Example #2
0
 /**
  * Builds a command.
  *
  * @param string      $sub_command  Sub command.
  * @param string|null $param_string Parameter string.
  *
  * @return Command
  */
 public function getCommand($sub_command, $param_string = null)
 {
     $command_line = $this->buildCommand($sub_command, $param_string);
     $command = new Command($command_line, $this->_io, $this->_cacheManager, $this->_processFactory);
     if (isset($this->_nextCommandCacheDuration)) {
         $command->setCacheDuration($this->_nextCommandCacheDuration);
         $this->_nextCommandCacheDuration = null;
     }
     return $command;
 }