Skip to content

Commit 2bd056d

Browse files
author
Alexander Obuhovich
committed
Remove interactivity support from "Repository\Command" class
Closes console-helpers#44
1 parent cb22f06 commit 2bd056d

File tree

4 files changed

+17
-56
lines changed

4 files changed

+17
-56
lines changed

src/SVNBuddy/Repository/Connector/Command.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public function setCacheDuration($duration)
127127
*/
128128
public function run($callback = null)
129129
{
130-
$this->_patchProcess();
131130
$command_line = $this->_process->getCommandLine();
132131
$cache_key = $this->_getCacheKey();
133132

@@ -159,29 +158,6 @@ public function run($callback = null)
159158
return $output;
160159
}
161160

162-
/**
163-
* Patches process command line for interactivity.
164-
*
165-
* @return void
166-
*/
167-
private function _patchProcess()
168-
{
169-
$interactivity_part = ' --non-interactive ';
170-
$command_line = $this->_process->getCommandLine();
171-
172-
if ( $this->_isInteractive ) {
173-
$command_line = str_replace($interactivity_part, ' ', $command_line);
174-
$this->_process->setInput(STDIN);
175-
}
176-
elseif ( strpos($command_line, $interactivity_part) === false ) {
177-
$parts = explode(' ', $command_line, 2);
178-
$command_line = $parts[0] . ' --non-interactive ' . $parts[1];
179-
$this->_process->setInput('');
180-
}
181-
182-
$this->_process->setCommandLine($command_line);
183-
}
184-
185161
/**
186162
* Returns cache key for a command.
187163
*

src/SVNBuddy/Repository/Connector/Connector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ protected function prepareSvnCommand()
101101
$username = $this->_configEditor->get('repository-connector.username');
102102
$password = $this->_configEditor->get('repository-connector.password');
103103

104+
$this->_svnCommand .= ' --non-interactive';
105+
104106
if ( $username ) {
105107
$this->_svnCommand .= ' --username ' . $username;
106108
}

tests/SVNBuddy/Repository/Connector/CommandTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,12 @@ protected function setUp()
5858

5959
public function testRunWithoutCallback()
6060
{
61-
$this->_process->getCommandLine()->willReturn('svn log --limit 5')->shouldBeCalled();
62-
$this->_process->setInput('')->shouldBeCalled();
61+
$this->_process->getCommandLine()->willReturn('svn --non-interactive log --limit 5')->shouldBeCalled();
6362
$this->_process->mustRun(null)->shouldBeCalled();
6463
$this->_process->getOutput()->willReturn('OK')->shouldBeCalled();
6564

6665
$this->_io->isVerbose()->willReturn(false);
6766

68-
$this->_process
69-
->setCommandLine('svn --non-interactive log --limit 5')
70-
->will(function ($args, $process) {
71-
$process->getCommandLine()->willReturn($args[0])->shouldBeCalled();
72-
})
73-
->shouldBeCalled();
74-
7567
$this->assertEquals('OK', $this->_command->run());
7668
}
7769

tests/SVNBuddy/Repository/Connector/ConnectorTest.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,52 +101,52 @@ public function testConfigUsernameUsed()
101101
{
102102
$repository_connector = $this->_createRepositoryConnector('user', '');
103103

104-
$this->_expectCommand('svn --username user --version', 'OK');
104+
$this->_expectCommand('svn --non-interactive --username user --version', 'OK');
105105
$this->assertEquals('OK', $repository_connector->getCommand('--version')->run());
106106
}
107107

108108
public function testConfigPasswordUsed()
109109
{
110110
$repository_connector = $this->_createRepositoryConnector('', 'pass');
111111

112-
$this->_expectCommand('svn --password pass --version', 'OK');
112+
$this->_expectCommand('svn --non-interactive --password pass --version', 'OK');
113113
$this->assertEquals('OK', $repository_connector->getCommand('--version')->run());
114114
}
115115

116116
public function testSimpleCommand()
117117
{
118-
$this->_expectCommand('svn --version', 'OK');
118+
$this->_expectCommand('svn --non-interactive --version', 'OK');
119119
$this->assertEquals('OK', $this->_repositoryConnector->getCommand('--version')->run());
120120
}
121121

122122
public function testCommandWithParams()
123123
{
124-
$this->_expectCommand('svn log -r 12', 'OK');
124+
$this->_expectCommand('svn --non-interactive log -r 12', 'OK');
125125
$this->assertEquals('OK', $this->_repositoryConnector->getCommand('log', '-r 12')->run());
126126
}
127127

128128
public function testCommandWithPath()
129129
{
130-
$this->_expectCommand("svn log 'path/to/folder'", 'OK');
130+
$this->_expectCommand("svn --non-interactive log 'path/to/folder'", 'OK');
131131
$this->assertEquals('OK', $this->_repositoryConnector->getCommand('log', '{path/to/folder}')->run());
132132
}
133133

134134
public function testCommandWithPathAndLeadingSlash()
135135
{
136-
$this->_expectCommand("svn log '/path/to/folder'", 'OK');
136+
$this->_expectCommand("svn --non-interactive log '/path/to/folder'", 'OK');
137137
$this->assertEquals('OK', $this->_repositoryConnector->getCommand('log', '{/path/to/folder}')->run());
138138
}
139139

140140
public function testCommandWithPathAndParams()
141141
{
142-
$this->_expectCommand("svn log -r 12 'path/to/folder'", 'OK');
142+
$this->_expectCommand("svn --non-interactive log -r 12 'path/to/folder'", 'OK');
143143
$this->assertEquals('OK', $this->_repositoryConnector->getCommand('log', '-r 12 {path/to/folder}')->run());
144144
}
145145

146146
public function testCommandThatFails()
147147
{
148148
$thrown_exception = null;
149-
$this->_expectCommand('svn any', '', false);
149+
$this->_expectCommand('svn --non-interactive any', '', false);
150150

151151
try {
152152
$this->_repositoryConnector->getCommand('any')->run();
@@ -173,7 +173,7 @@ public function testCommandThatFails()
173173

174174
public function testGetPropertyFound()
175175
{
176-
$this->_expectCommand("svn propget test-p 'the/path'", 'OK');
176+
$this->_expectCommand("svn --non-interactive propget test-p 'the/path'", 'OK');
177177

178178
$this->assertEquals(
179179
'OK',
@@ -196,32 +196,23 @@ public function testGetPropertyNotFound()
196196
0
197197
);
198198

199-
$this->_expectCommand("svn propget test-p 'the/path'", '', false);
199+
$this->_expectCommand("svn --non-interactive propget test-p 'the/path'", '', false);
200200

201201
$this->_repositoryConnector->getProperty('test-p', 'the/path');
202202
}
203203

204204
/**
205205
* Sets expectation for specific command.
206206
*
207-
* @param string $command Command.
208-
* @param string $output Output.
209-
* @param boolean $is_successful Should command be successful.
210-
* @param boolean $is_interactive Is interactive.
207+
* @param string $command Command.
208+
* @param string $output Output.
209+
* @param boolean $is_successful Should command be successful.
211210
*
212211
* @return void
213212
*/
214-
private function _expectCommand($command, $output, $is_successful = true, $is_interactive = false)
213+
private function _expectCommand($command, $output, $is_successful = true)
215214
{
216-
if ( !$is_interactive ) {
217-
$this->_process->setInput('')->shouldBeCalled();
218-
}
219-
220-
$patched_command = preg_replace('/^svn /', 'svn --non-interactive ', $command);
221215
$this->_process->getCommandLine()->willReturn($command)->shouldBeCalled();
222-
$this->_process->setCommandLine($patched_command)->will(function ($args, $process) {
223-
$process->getCommandLine()->willReturn($args[0]);
224-
})->shouldBeCalled();
225216

226217
$expectation = $this->_process->mustRun(null)->shouldBeCalled();
227218

0 commit comments

Comments
 (0)