4
4
5
5
use BrainMaestro \GitHooks \Commands \AddCommand ;
6
6
use BrainMaestro \GitHooks \Hook ;
7
- use Symfony \Component \Console \Application ;
8
7
use Symfony \Component \Console \Tester \CommandTester ;
8
+ use Symfony \Component \Console \Output \OutputInterface ;
9
9
10
10
class AddCommandTest extends TestCase
11
11
{
@@ -54,11 +54,13 @@ public function it_adds_shebang_to_hooks_on_windows()
54
54
public function it_does_not_add_hooks_that_already_exist ()
55
55
{
56
56
self ::createHooks ();
57
- $ this ->commandTester ->execute ([]);
57
+ $ this ->commandTester ->execute ([], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
58
58
59
59
foreach (array_keys (self ::$ hooks ) as $ hook ) {
60
60
$ this ->assertContains ("{$ hook } already exists " , $ this ->commandTester ->getDisplay ());
61
61
}
62
+
63
+ $ this ->assertContains ('No hooks were added. Try updating ' , $ this ->commandTester ->getDisplay ());
62
64
}
63
65
64
66
/**
@@ -79,7 +81,7 @@ public function it_overrides_hooks_that_already_exist()
79
81
*/
80
82
public function it_correctly_creates_the_hook_lock_file ()
81
83
{
82
- $ this ->commandTester ->execute ([]);
84
+ $ this ->commandTester ->execute ([], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
83
85
84
86
$ this ->assertContains ('Created ' . Hook::LOCK_FILE . ' file ' , $ this ->commandTester ->getDisplay ());
85
87
$ this ->assertFileExists (Hook::LOCK_FILE );
@@ -91,7 +93,7 @@ public function it_correctly_creates_the_hook_lock_file()
91
93
*/
92
94
public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_passed ()
93
95
{
94
- $ this ->commandTester ->execute (['--no-lock ' => true ]);
96
+ $ this ->commandTester ->execute (['--no-lock ' => true ], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
95
97
96
98
$ this ->assertContains ('Skipped creating a ' . Hook::LOCK_FILE . ' file ' , $ this ->commandTester ->getDisplay ());
97
99
$ this ->assertFileNotExists (Hook::LOCK_FILE );
@@ -102,7 +104,7 @@ public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_p
102
104
*/
103
105
public function it_does_not_ignore_the_hook_lock_file ()
104
106
{
105
- $ this ->commandTester ->execute ([]);
107
+ $ this ->commandTester ->execute ([], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
106
108
107
109
$ this ->assertContains ('Skipped adding ' . Hook::LOCK_FILE . ' to .gitignore ' , $ this ->commandTester ->getDisplay ());
108
110
$ this ->assertFalse (strpos (file_get_contents ('.gitignore ' ), Hook::LOCK_FILE ));
@@ -113,7 +115,7 @@ public function it_does_not_ignore_the_hook_lock_file()
113
115
*/
114
116
public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passed ()
115
117
{
116
- $ this ->commandTester ->execute (['--ignore-lock ' => true ]);
118
+ $ this ->commandTester ->execute (['--ignore-lock ' => true ], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
117
119
118
120
$ this ->assertContains ('Added ' . Hook::LOCK_FILE . ' to .gitignore ' , $ this ->commandTester ->getDisplay ());
119
121
$ this ->assertTrue (strpos (file_get_contents ('.gitignore ' ), Hook::LOCK_FILE ) !== false );
@@ -216,7 +218,10 @@ public function it_adds_global_git_hooks()
216
218
217
219
self ::createTestComposerFile ($ gitDir );
218
220
219
- $ this ->commandTester ->execute (['--global ' => true , '--git-dir ' => $ gitDir ]);
221
+ $ this ->commandTester ->execute (
222
+ ['--global ' => true , '--git-dir ' => $ gitDir ],
223
+ ['verbosity ' => OutputInterface::VERBOSITY_VERBOSE ]
224
+ );
220
225
221
226
foreach (array_keys (self ::$ hooks ) as $ hook ) {
222
227
$ this ->assertContains ("Added {$ hook } hook " , $ this ->commandTester ->getDisplay ());
@@ -244,7 +249,10 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
244
249
245
250
self ::createTestComposerFile ($ gitDir );
246
251
247
- $ this ->commandTester ->execute (['--global ' => true , '--git-dir ' => $ gitDir ]);
252
+ $ this ->commandTester ->execute (
253
+ ['--global ' => true , '--git-dir ' => $ gitDir ],
254
+ ['verbosity ' => OutputInterface::VERBOSITY_VERBOSE ]
255
+ );
248
256
249
257
foreach (array_keys (self ::$ hooks ) as $ hook ) {
250
258
$ this ->assertContains ("Added {$ hook } hook " , $ this ->commandTester ->getDisplay ());
@@ -253,7 +261,7 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
253
261
254
262
$ hookDir = realpath ("{$ gitDir }/hooks " );
255
263
$ this ->assertContains (
256
- "About to modify global git hook path. Previous value was [ {$ previousHookDir }] " ,
264
+ "About to modify global git hook path. Previous value was {$ previousHookDir }" ,
257
265
$ this ->commandTester ->getDisplay ()
258
266
);
259
267
$ this ->assertContains ("Global git hook path set to {$ hookDir }" , $ this ->commandTester ->getDisplay ());
@@ -272,15 +280,18 @@ public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_ma
272
280
273
281
self ::createTestComposerFile ($ gitDir );
274
282
275
- $ this ->commandTester ->execute (['--global ' => true , '--git-dir ' => $ gitDir ]);
283
+ $ this ->commandTester ->execute (
284
+ ['--global ' => true , '--git-dir ' => $ gitDir ],
285
+ ['verbosity ' => OutputInterface::VERBOSITY_VERBOSE ]
286
+ );
276
287
277
288
foreach (array_keys (self ::$ hooks ) as $ hook ) {
278
289
$ this ->assertContains ("Added {$ hook } hook " , $ this ->commandTester ->getDisplay ());
279
290
$ this ->assertFileExists ("{$ hookDir }/ {$ hook }" );
280
291
}
281
292
282
293
$ this ->assertNotContains (
283
- "About to modify global git hook path. Previous value was [ {$ hookDir }] " ,
294
+ "About to modify global git hook path. Previous value was {$ hookDir }" ,
284
295
$ this ->commandTester ->getDisplay ()
285
296
);
286
297
$ this ->assertNotContains ("Global git hook path set to {$ hookDir }" , $ this ->commandTester ->getDisplay ());
@@ -300,7 +311,7 @@ public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided
300
311
301
312
self ::createTestComposerFile ($ gitDir );
302
313
303
- $ this ->commandTester ->execute (['--global ' => true ]);
314
+ $ this ->commandTester ->execute (['--global ' => true ], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
304
315
305
316
foreach (array_keys (self ::$ hooks ) as $ hook ) {
306
317
$ this ->assertContains ("Added {$ hook } hook " , $ this ->commandTester ->getDisplay ());
@@ -310,7 +321,7 @@ public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided
310
321
$ gitDir = realpath ('test-global-composer-home-dir ' );
311
322
$ hookDir = "{$ gitDir }/hooks " ;
312
323
$ this ->assertContains (
313
- "No global git hook path was provided. Falling back to COMPOSER_HOME [ {$ gitDir }] " ,
324
+ "No global git hook path was provided. Falling back to COMPOSER_HOME {$ gitDir }" ,
314
325
$ this ->commandTester ->getDisplay ()
315
326
);
316
327
$ this ->assertContains (
@@ -332,7 +343,7 @@ public function it_fails_if_global_hook_dir_is_missing()
332
343
333
344
shell_exec ('git config --global --unset core.hooksPath ' );
334
345
335
- $ this ->commandTester ->execute (['--global ' => true ]);
346
+ $ this ->commandTester ->execute (['--global ' => true ], [ ' verbosity ' => OutputInterface:: VERBOSITY_VERBOSE ] );
336
347
337
348
foreach (array_keys (self ::$ hooks ) as $ hook ) {
338
349
$ this ->assertNotContains ("Updated {$ hook } hook " , $ this ->commandTester ->getDisplay ());
0 commit comments