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());
    }
 /**
  * @dataProvider refreshWithoutCacheWithOutputDataProvider
  */
 public function testRefreshWithoutCacheWithOutput($is_verbose)
 {
     // Create progress bar for repository.
     $repository_progress_bar = $this->prophesize('Symfony\\Component\\Console\\Helper\\ProgressBar');
     $repository_progress_bar->setMessage(' * Reading missing revisions:')->shouldBeCalled();
     $repository_progress_bar->setFormat('%message% %current%/%max% [%bar%] <info>%percent:3s%%</info> %elapsed:6s%/%estimated:-6s% <info>%memory:-10s%</info>')->shouldBeCalled();
     $repository_progress_bar->start()->shouldBeCalled();
     $repository_progress_bar->advance()->shouldBeCalled();
     $repository_progress_bar->clear()->shouldBeCalled();
     $this->io->createProgressBar(3)->willReturn($repository_progress_bar)->shouldBeCalled();
     // Create progress bar for database.
     $database_progress_bar = $this->prophesize('Symfony\\Component\\Console\\Helper\\ProgressBar');
     $database_progress_bar->setMessage(' * Reading missing revisions:')->shouldBeCalled();
     $database_progress_bar->setFormat('%message% %current% [%bar%] %elapsed:6s% <info>%memory:-10s%</info>')->shouldBeCalled();
     $database_progress_bar->start()->shouldBeCalled();
     $database_progress_bar->advance()->shouldBeCalled();
     $database_progress_bar->finish()->shouldBeCalled();
     $this->io->createProgressBar()->willReturn($database_progress_bar)->shouldBeCalled();
     $this->io->writeln('')->shouldBeCalled();
     $this->io->isVerbose()->willReturn($is_verbose);
     if ($is_verbose) {
         $this->io->writeln('<debug>Combined Plugin Statistics:</debug>')->shouldBeCalled();
     }
     $this->testRefreshWithoutCacheWithoutOutput($this->io->reveal(), $database_progress_bar->reveal(), $is_verbose);
 }
 /**
  * Sets expectation for specific command.
  *
  * @param string       $command    Command.
  * @param string       $output     Output.
  * @param string|null  $error_msg  Error msg.
  * @param integer $error_code Error code.
  */
 private function _expectCommand($command, $output, $error_msg = null, $error_code = 0)
 {
     $process = $this->prophesize('Symfony\\Component\\Process\\Process');
     $expectation = $process->mustRun(strpos($command, 'upgrade') !== false ? Argument::type('callable') : null)->shouldBeCalled();
     if (isset($error_code) && isset($error_msg)) {
         $expectation->willThrow(new RepositoryCommandException($command, 'svn: E' . $error_code . ': ' . $error_msg));
     } else {
         $expectation->willReturn(null);
         $process->getOutput()->willReturn($output)->shouldBeCalled();
     }
     $this->_io->isVerbose()->willReturn(false);
     $this->_io->isDebug()->willReturn(false);
     $this->_processFactory->createProcess($command, 1200)->willReturn($process)->shouldBeCalled();
 }