6
6
use BrainMaestro \GitHooks \Hook ;
7
7
use Symfony \Component \Console \Tester \CommandTester ;
8
8
use Symfony \Component \Console \Output \OutputInterface ;
9
+ use PHPUnit \Framework \Attributes \Test ;
9
10
10
11
class AddCommandTest extends TestCase
11
12
{
@@ -16,9 +17,7 @@ public function init()
16
17
$ this ->commandTester = new CommandTester (new AddCommand ());
17
18
}
18
19
19
- /**
20
- * @test
21
- */
20
+ #[Test]
22
21
public function it_adds_hooks_that_do_not_already_exist ()
23
22
{
24
23
$ this ->commandTester ->execute ([]);
@@ -28,9 +27,7 @@ public function it_adds_hooks_that_do_not_already_exist()
28
27
}
29
28
}
30
29
31
- /**
32
- * @test
33
- */
30
+ #[Test]
34
31
public function it_doesnt_allow_to_add_custom_hooks_by_default ()
35
32
{
36
33
$ customHooks = [
@@ -47,9 +44,7 @@ public function it_doesnt_allow_to_add_custom_hooks_by_default()
47
44
);
48
45
}
49
46
50
- /**
51
- * @test
52
- */
47
+ #[Test]
53
48
public function it_allows_to_add_custom_hooks_specified_in_config_section ()
54
49
{
55
50
$ customHooks = [
@@ -74,9 +69,7 @@ public function it_allows_to_add_custom_hooks_specified_in_config_section()
74
69
);
75
70
}
76
71
77
- /**
78
- * @test
79
- */
72
+ #[Test]
80
73
public function it_adds_shebang_to_hooks_on_windows ()
81
74
{
82
75
if (! is_windows ()) {
@@ -94,9 +87,7 @@ public function it_adds_shebang_to_hooks_on_windows()
94
87
}
95
88
}
96
89
97
- /**
98
- * @test
99
- */
90
+ #[Test]
100
91
public function it_does_not_add_hooks_that_already_exist ()
101
92
{
102
93
self ::createHooks ();
@@ -109,9 +100,7 @@ public function it_does_not_add_hooks_that_already_exist()
109
100
$ this ->assertStringContainsString ('No hooks were added. Try updating ' , $ this ->commandTester ->getDisplay ());
110
101
}
111
102
112
- /**
113
- * @test
114
- */
103
+ #[Test]
115
104
public function it_detects_existing_correct_hooks ()
116
105
{
117
106
$ originalHooks = self ::$ hooks ;
@@ -131,9 +120,7 @@ public function it_detects_existing_correct_hooks()
131
120
self ::$ hooks = $ originalHooks ;
132
121
}
133
122
134
- /**
135
- * @test
136
- */
123
+ #[Test]
137
124
public function it_overrides_hooks_that_already_exist ()
138
125
{
139
126
self ::createHooks ();
@@ -144,9 +131,7 @@ public function it_overrides_hooks_that_already_exist()
144
131
}
145
132
}
146
133
147
- /**
148
- * @test
149
- */
134
+ #[Test]
150
135
public function it_correctly_creates_the_hook_lock_file ()
151
136
{
152
137
$ currentDir = realpath (getcwd ());
@@ -178,9 +163,7 @@ public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
178
163
self ::rmdir ('../ ' . $ lockDir );
179
164
}
180
165
181
- /**
182
- * @test
183
- */
166
+ #[Test]
184
167
public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_passed ()
185
168
{
186
169
$ currentDir = realpath (getcwd ());
@@ -190,9 +173,7 @@ public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_p
190
173
$ this ->assertFileDoesNotExist (Hook::LOCK_FILE );
191
174
}
192
175
193
- /**
194
- * @test
195
- */
176
+ #[Test]
196
177
public function it_does_not_ignore_the_hook_lock_file ()
197
178
{
198
179
$ currentDir = realpath (getcwd ());
@@ -202,9 +183,7 @@ public function it_does_not_ignore_the_hook_lock_file()
202
183
$ this ->assertFalse (strpos (file_get_contents ('.gitignore ' ), Hook::LOCK_FILE ));
203
184
}
204
185
205
- /**
206
- * @test
207
- */
186
+ #[Test]
208
187
public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passed ()
209
188
{
210
189
$ this ->commandTester ->execute (['--ignore-lock ' => true ], ['verbosity ' => OutputInterface::VERBOSITY_VERBOSE ]);
@@ -213,9 +192,7 @@ public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passe
213
192
$ this ->assertTrue (strpos (file_get_contents ('.gitignore ' ), Hook::LOCK_FILE ) !== false );
214
193
}
215
194
216
- /**
217
- * @test
218
- */
195
+ #[Test]
219
196
public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored ()
220
197
{
221
198
file_put_contents ('.gitignore ' , Hook::LOCK_FILE . PHP_EOL , FILE_APPEND );
@@ -225,9 +202,7 @@ public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
225
202
$ this ->assertTrue (strpos (file_get_contents ('.gitignore ' ), Hook::LOCK_FILE ) !== false );
226
203
}
227
204
228
- /**
229
- * @test
230
- */
205
+ #[Test]
231
206
public function it_uses_a_different_git_path_if_specified ()
232
207
{
233
208
$ gitDir = 'test-git-dir ' ;
@@ -242,9 +217,7 @@ public function it_uses_a_different_git_path_if_specified()
242
217
}
243
218
}
244
219
245
- /**
246
- * @test
247
- */
220
+ #[Test]
248
221
public function it_does_not_create_a_lock_file_when_no_hooks_were_added ()
249
222
{
250
223
self ::removeTestComposerFile (); // so that there will be no hooks to add
@@ -256,9 +229,7 @@ public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
256
229
}
257
230
}
258
231
259
- /**
260
- * @test
261
- */
232
+ #[Test]
262
233
public function it_create_git_hooks_path_when_hooks_dir_not_exists ()
263
234
{
264
235
$ gitDir = 'test-git-dir ' ;
@@ -272,9 +243,7 @@ public function it_create_git_hooks_path_when_hooks_dir_not_exists()
272
243
}
273
244
}
274
245
275
- /**
276
- * @test
277
- */
246
+ #[Test]
278
247
public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed ()
279
248
{
280
249
$ this ->commandTester ->execute (['--force-win ' => true ]);
@@ -288,9 +257,7 @@ public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
288
257
}
289
258
}
290
259
291
- /**
292
- * @test
293
- */
260
+ #[Test]
294
261
public function it_handles_commands_defined_in_an_array ()
295
262
{
296
263
$ hooks = [
@@ -313,9 +280,7 @@ public function it_handles_commands_defined_in_an_array()
313
280
}
314
281
315
282
316
- /**
317
- * @test
318
- */
283
+ #[Test]
319
284
public function it_uses_commands_sequence_for_configured_hooks_only ()
320
285
{
321
286
$ hooks = [
@@ -350,9 +315,7 @@ public function it_uses_commands_sequence_for_configured_hooks_only()
350
315
$ this ->assertStringContainsString ($ expected , $ content );
351
316
}
352
317
353
- /**
354
- * @test
355
- */
318
+ #[Test]
356
319
public function it_adds_global_git_hooks ()
357
320
{
358
321
$ gitDir = 'test-global-git-dir ' ;
@@ -379,9 +342,7 @@ public function it_adds_global_git_hooks()
379
342
$ this ->assertEquals ($ hookDir , global_hook_dir ());
380
343
}
381
344
382
- /**
383
- * @test
384
- */
345
+ #[Test]
385
346
public function it_adds_global_git_hooks_and_shows_previous_global_dir ()
386
347
{
387
348
$ gitDir = 'test-global-git-dir ' ;
@@ -410,9 +371,7 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
410
371
$ this ->assertEquals ($ hookDir , global_hook_dir ());
411
372
}
412
373
413
- /**
414
- * @test
415
- */
374
+ #[Test]
416
375
public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_matches_new_value ()
417
376
{
418
377
$ gitDir = 'test-global-git-dir ' ;
@@ -440,9 +399,7 @@ public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_ma
440
399
$ this ->assertEquals ($ hookDir , global_hook_dir ());
441
400
}
442
401
443
- /**
444
- * @test
445
- */
402
+ #[Test]
446
403
public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided ()
447
404
{
448
405
$ gitDir = 'test-global-composer-home-dir ' ;
@@ -474,9 +431,7 @@ public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided
474
431
$ this ->assertEquals ($ hookDir , global_hook_dir ());
475
432
}
476
433
477
- /**
478
- * @test
479
- */
434
+ #[Test]
480
435
public function it_fails_if_global_hook_dir_is_missing ()
481
436
{
482
437
putenv ('COMPOSER_HOME= ' );
@@ -495,9 +450,7 @@ public function it_fails_if_global_hook_dir_is_missing()
495
450
);
496
451
}
497
452
498
- /**
499
- * @test
500
- */
453
+ #[Test]
501
454
public function it_adds_hooks_correctly_in_a_git_worktree ()
502
455
{
503
456
$ currentDir = realpath (getcwd ());
0 commit comments