/** * @dataProvider runWithCacheDataProvider */ public function testRunWithExistingCache($duration, $invalidator, $use_callback, $is_xml) { if ($is_xml) { $command_line = 'svn log --xml'; $process_output = '<log><logentry/></log>'; } else { $command_line = 'svn log'; $process_output = 'OK'; } $callback_output = null; $callback = $this->createRunCallback($use_callback, $callback_output); $this->_process->getCommandLine()->willReturn($command_line)->shouldBeCalled(); $this->_process->mustRun($callback)->shouldNotBeCalled(); $this->_cacheManager->getCache('command:' . $command_line, $invalidator)->willReturn($process_output)->shouldBeCalled(); $this->_cacheManager->setCache(Argument::any())->shouldNotBeCalled(); if (isset($duration)) { $this->_command->setCacheDuration($duration); } if (isset($invalidator)) { $this->_command->setCacheInvalidator($invalidator); } $this->assertCommandOutput($callback, $is_xml, $process_output); if ($use_callback) { $this->assertEquals($process_output, $callback_output); } }
/** * 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; }