Skip to content

Commit 5cdab4a

Browse files
committed
Refactor code have single place for an SVN command Idle timeout changing (if needed)
1 parent 7ecc0dd commit 5cdab4a

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/SVNBuddy/Repository/Connector/Command.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
class Command
2323
{
2424

25+
const IDLE_TIMEOUT = 180; // 3 minutes.
26+
2527
/**
2628
* Process factory.
2729
*
@@ -213,7 +215,7 @@ private function _getCacheKey()
213215
*/
214216
private function _doRun($callback = null)
215217
{
216-
$process = $this->_processFactory->createProcess($this->_commandLine, 180); // Idle timeout: 3 minutes.
218+
$process = $this->_processFactory->createProcess($this->_commandLine, self::IDLE_TIMEOUT);
217219
$command_string = (string)$this;
218220

219221
try {

tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ConsoleHelpers\SVNBuddy\Cache\CacheManager;
1717
use ConsoleHelpers\SVNBuddy\Exception\RepositoryCommandException;
1818
use ConsoleHelpers\SVNBuddy\Process\IProcessFactory;
19+
use ConsoleHelpers\SVNBuddy\Repository\Connector\Command;
1920
use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory;
2021
use Prophecy\Argument;
2122
use Prophecy\Prophecy\ObjectProphecy;
@@ -73,9 +74,13 @@ protected function setupTest()
7374

7475
// To get nice exception back when unexpected command is executed.
7576
$this->_processFactory
76-
->createProcess(Argument::any(), 180)
77+
->createProcess(Argument::any(), Command::IDLE_TIMEOUT)
7778
->will(function (array $args) {
78-
throw new \LogicException('The createProcess("' . implode(' ', $args[0]) . '", 180) call wasn\'t expected.');
79+
throw new \LogicException(sprintf(
80+
'The createProcess("%s", %s) call wasn\'t expected.',
81+
implode(' ', $args[0]),
82+
Command::IDLE_TIMEOUT
83+
));
7984
});
8085

8186
$this->_commandFactory = $this->_createCommandFactory('', '');
@@ -176,7 +181,7 @@ private function _expectCommand(array $command, $output, $error_msg = null, $err
176181
$this->_io->isVerbose()->willReturn(false);
177182
$this->_io->isDebug()->willReturn(false);
178183

179-
$this->_processFactory->createProcess($command, 180)->willReturn($process)->shouldBeCalled();
184+
$this->_processFactory->createProcess($command, Command::IDLE_TIMEOUT)->willReturn($process)->shouldBeCalled();
180185
}
181186

182187
/**

tests/SVNBuddy/Repository/Connector/CommandTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ public static function cacheKeyFormingDataProvider()
531531
private function _createCommand(array $command_line, $use_process = true)
532532
{
533533
if ( $use_process ) {
534-
$this->_processFactory->createProcess($command_line, 180)->willReturn($this->_process)->shouldBeCalled();
534+
$this->_processFactory->createProcess($command_line, Command::IDLE_TIMEOUT)
535+
->willReturn($this->_process)
536+
->shouldBeCalled();
535537
}
536538

537539
return new Command(

0 commit comments

Comments
 (0)