@@ -73,180 +73,106 @@ protected function setUp()
73
73
// Called from "__destruct".
74
74
$ this ->_process ->stop ();
75
75
76
- $ with_exceptions = array (
77
- 'testCommandThatFails ' ,
78
- 'testGetPropertyNotFound ' ,
79
- );
80
-
81
- $ this ->_repositoryConnector = $ this ->_createRepositoryConnector (
82
- '' ,
83
- '' ,
84
- in_array ($ this ->getName (false ), $ with_exceptions ) ? null : false
85
- );
76
+ $ this ->_repositoryConnector = $ this ->_createRepositoryConnector ('' , '' );
86
77
}
87
78
88
- public function testConfigUsernameUsed ()
79
+ /**
80
+ * @dataProvider baseCommandBuildingDataProvider
81
+ */
82
+ public function testBaseCommandBuilding ($ username , $ password , $ expected_command )
89
83
{
90
- $ repository_connector = $ this ->_createRepositoryConnector (' user ' , '' );
84
+ $ repository_connector = $ this ->_createRepositoryConnector ($ username , $ password );
91
85
92
- $ this ->_expectCommand (' svn --non-interactive --username user --version ' , 'OK ' );
93
- $ this ->assertEquals ('OK ' , $ repository_connector ->getCommand ('--version ' )->run ());
86
+ $ this ->_expectCommand ($ expected_command , 'OK ' );
87
+ $ this ->assertEquals ('OK ' , $ repository_connector ->getCommand ('' , ' --version ' )->run ());
94
88
}
95
89
96
- public function testConfigPasswordUsed ()
90
+ public function baseCommandBuildingDataProvider ()
97
91
{
98
- $ repository_connector = $ this ->_createRepositoryConnector ('' , 'pass ' );
99
-
100
- $ this ->_expectCommand ('svn --non-interactive --password pass --version ' , 'OK ' );
101
- $ this ->assertEquals ('OK ' , $ repository_connector ->getCommand ('--version ' )->run ());
92
+ return array (
93
+ 'no username, no password ' => array ('' , '' , 'svn --non-interactive --version ' ),
94
+ 'username, no password ' => array ('user ' , '' , 'svn --non-interactive --username user --version ' ),
95
+ 'no username, password ' => array ('' , 'pass ' , 'svn --non-interactive --password pass --version ' ),
96
+ 'username, password ' => array (
97
+ 'user ' ,
98
+ 'pass ' ,
99
+ 'svn --non-interactive --username user --password pass --version ' ,
100
+ ),
101
+ );
102
102
}
103
103
104
- public function testSimpleCommand ()
104
+ public function testCommandWithoutSubCommand ()
105
105
{
106
106
$ this ->_expectCommand ('svn --non-interactive --version ' , 'OK ' );
107
- $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('--version ' )->run ());
108
- }
109
-
110
- public function testCommandWithParams ()
111
- {
112
- $ this ->_expectCommand ('svn --non-interactive log -r 12 ' , 'OK ' );
113
- $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' , '-r 12 ' )->run ());
114
- }
115
-
116
- public function testCommandWithPath ()
117
- {
118
- $ this ->_expectCommand ("svn --non-interactive log 'path/to/folder' " , 'OK ' );
119
- $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' , '{path/to/folder} ' )->run ());
107
+ $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('' , '--version ' )->run ());
120
108
}
121
109
122
- public function testCommandWithPathAndLeadingSlash ()
110
+ public function testCommandWithoutParams ()
123
111
{
124
- $ this ->_expectCommand (" svn --non-interactive log '/path/to/folder' " , 'OK ' );
125
- $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' , ' {/path/to/folder} ' )->run ());
112
+ $ this ->_expectCommand (' svn --non-interactive log ' , 'OK ' );
113
+ $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' )->run ());
126
114
}
127
115
128
- public function testCommandWithPathAndParams ()
116
+ /**
117
+ * @dataProvider commandWithParamsDataProvider
118
+ */
119
+ public function testCommandWithParams ($ params , $ expected_command )
129
120
{
130
- $ this ->_expectCommand (" svn --non-interactive log -r 12 'path/to/folder' " , 'OK ' );
131
- $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' , ' -r 12 {path/to/folder} ' )->run ());
121
+ $ this ->_expectCommand ($ expected_command , 'OK ' );
122
+ $ this ->assertEquals ('OK ' , $ this ->_repositoryConnector ->getCommand ('log ' , $ params )->run ());
132
123
}
133
124
134
- public function testCommandThatFails ()
125
+ public function commandWithParamsDataProvider ()
135
126
{
136
- $ thrown_exception = null ;
137
- $ this ->_expectCommand ('svn --non-interactive any ' , '' , false );
138
-
139
- try {
140
- $ this ->_repositoryConnector ->getCommand ('any ' )->run ();
141
- }
142
- catch ( \Exception $ thrown_exception ) {
143
- $ this ->assertEquals (
144
- 'ConsoleHelpers \\SVNBuddy \\Exception \\RepositoryCommandException ' ,
145
- get_class ($ thrown_exception ),
146
- 'Exception of correct class was thrown '
147
- );
148
- }
149
-
150
- $ this ->assertNotNull ($ thrown_exception , 'Exception was thrown when command execution failed ' );
151
-
152
- $ error_msg = <<<MSG
153
- Command:
154
- svn --non-interactive any
155
- Error #0:
156
- error output
157
- MSG ;
158
-
159
- $ this ->assertEquals ($ error_msg , $ thrown_exception ->getMessage ());
127
+ return array (
128
+ 'regular param ' => array ('-r 12 ' , 'svn --non-interactive log -r 12 ' ),
129
+ 'path param ' => array ('{path/to/folder} ' , "svn --non-interactive log 'path/to/folder' " ),
130
+ 'regular and path param ' => array (
131
+ '-r 12 {path/to/folder} ' ,
132
+ "svn --non-interactive log -r 12 'path/to/folder' " ,
133
+ ),
134
+ );
160
135
}
161
136
162
- public function testGetPropertyFound ()
137
+ public function testGetProperty ()
163
138
{
164
- $ this ->_expectCommand ("svn --non-interactive propget test-p 'the/path' " , 'OK ' );
139
+ $ this ->_expectCommand ("svn --non-interactive propget prop-name 'the/path' " , 'OK ' );
165
140
166
141
$ this ->assertEquals (
167
142
'OK ' ,
168
- $ this ->_repositoryConnector ->getProperty ('test-p ' , 'the/path ' )
169
- );
170
- }
171
-
172
- public function testGetPropertyNotFound ()
173
- {
174
- $ exception_msg = <<<MSG
175
- Command:
176
- svn --non-interactive propget test-p 'the/path'
177
- Error #0:
178
- error output
179
- MSG ;
180
-
181
- $ this ->setExpectedException (
182
- 'ConsoleHelpers \\SVNBuddy \\Exception \\RepositoryCommandException ' ,
183
- $ exception_msg ,
184
- 0
143
+ $ this ->_repositoryConnector ->getProperty ('prop-name ' , 'the/path ' )
185
144
);
186
-
187
- $ this ->_expectCommand ("svn --non-interactive propget test-p 'the/path' " , '' , false );
188
-
189
- $ this ->_repositoryConnector ->getProperty ('test-p ' , 'the/path ' );
190
145
}
191
146
192
147
/**
193
148
* Sets expectation for specific command.
194
149
*
195
- * @param string $command Command.
196
- * @param string $output Output.
197
- * @param boolean $is_successful Should command be successful.
150
+ * @param string $command Command.
151
+ * @param string $output Output.
198
152
*
199
153
* @return void
200
154
*/
201
- private function _expectCommand ($ command , $ output, $ is_successful = true )
155
+ private function _expectCommand ($ command , $ output )
202
156
{
203
157
$ this ->_process ->getCommandLine ()->willReturn ($ command )->shouldBeCalled ();
204
-
205
- $ expectation = $ this ->_process ->mustRun (null )->shouldBeCalled ();
206
-
207
- if ( $ is_successful ) {
208
- $ this ->_process ->getOutput ()->willReturn ($ output )->shouldBeCalled ();
209
- }
210
- else {
211
- $ process = $ this ->_process ;
212
- $ expectation ->will (function () use ($ process ) {
213
- $ mock_definition = array (
214
- 'isSuccessful ' => false ,
215
- 'getExitCode ' => 1 ,
216
- 'getExitCodeText ' => 'exit code text ' ,
217
- 'isOutputDisabled ' => false ,
218
- 'getOutput ' => 'normal output ' ,
219
- 'getErrorOutput ' => 'error output ' ,
220
- );
221
-
222
- foreach ( $ mock_definition as $ method_name => $ return_value ) {
223
- $ process ->{$ method_name }()->willReturn ($ return_value )->shouldBeCalled ();
224
- }
225
-
226
- throw new ProcessFailedException ($ process ->reveal ());
227
- });
228
- }
158
+ $ this ->_process ->mustRun (null )->shouldBeCalled ();
159
+ $ this ->_process ->getOutput ()->willReturn ($ output )->shouldBeCalled ();
229
160
230
161
$ this ->_processFactory ->createProcess ($ command , 1200 )->willReturn ($ this ->_process )->shouldBeCalled ();
231
162
}
232
163
233
164
/**
234
165
* Creates repository connector.
235
166
*
236
- * @param string $svn_username Username.
237
- * @param string $svn_password Password.
238
- * @param boolean $is_verbose Is verbose.
167
+ * @param string $username Username.
168
+ * @param string $password Password.
239
169
*
240
170
* @return Connector
241
171
*/
242
- private function _createRepositoryConnector ($ svn_username , $ svn_password , $ is_verbose = false )
172
+ private function _createRepositoryConnector ($ username , $ password )
243
173
{
244
- $ this ->_configEditor ->get ('repository-connector.username ' )->willReturn ($ svn_username )->shouldBeCalled ();
245
- $ this ->_configEditor ->get ('repository-connector.password ' )->willReturn ($ svn_password )->shouldBeCalled ();
246
-
247
- if ( isset ($ is_verbose ) ) {
248
- $ this ->_io ->isVerbose ()->willReturn ($ is_verbose )->shouldBeCalled ();
249
- }
174
+ $ this ->_configEditor ->get ('repository-connector.username ' )->willReturn ($ username )->shouldBeCalled ();
175
+ $ this ->_configEditor ->get ('repository-connector.password ' )->willReturn ($ password )->shouldBeCalled ();
250
176
251
177
return new Connector (
252
178
$ this ->_configEditor ->reveal (),
0 commit comments