Skip to content

Commit c9d2707

Browse files
committed
Prepare for symfony 7
1 parent 3d197c4 commit c9d2707

11 files changed

+65
-159
lines changed

.github/workflows/php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
php: ['8.0', '8.1']
17+
php: ['8.0', '8.1', '8.2', '8.3']
1818

1919
steps:
2020
- name: Checkout

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ cghooks-temp-*
55
.php_cs.cache
66
phpunit.xml
77
cghooks.lock
8+
composer.lock
9+
.phpunit.result.cache

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.0|^8.1",
20-
"symfony/console": "^5.0|^6.0"
19+
"php": "^8.0",
20+
"symfony/console": "^5.0|^6.0|^7.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^9.5",
23+
"phpunit/phpunit": "^11",
2424
"friendsofphp/php-cs-fixer": "^3.0",
2525
"ext-json": "*"
2626
},

src/Commands/Command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract protected function init(InputInterface $input);
2323

2424
abstract protected function command();
2525

26-
final protected function execute(InputInterface $input, OutputInterface $output)
26+
final protected function execute(InputInterface $input, OutputInterface $output): int
2727
{
2828
$this->output = $output;
2929
$this->gitDir = $input->getOption('git-dir') ?: git_dir();

src/Commands/HookCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function configure()
3030
;
3131
}
3232

33-
protected function execute(InputInterface $input, OutputInterface $output)
33+
protected function execute(InputInterface $input, OutputInterface $output): int
3434
{
3535
$contents = Hook::getHookContents($this->composerDir, $this->contents, $this->hook);
3636
$outputMessage = [];

tests/AddCommandTest.php

+25-72
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use BrainMaestro\GitHooks\Hook;
77
use Symfony\Component\Console\Tester\CommandTester;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use PHPUnit\Framework\Attributes\Test;
910

1011
class AddCommandTest extends TestCase
1112
{
@@ -16,9 +17,7 @@ public function init()
1617
$this->commandTester = new CommandTester(new AddCommand());
1718
}
1819

19-
/**
20-
* @test
21-
*/
20+
#[Test]
2221
public function it_adds_hooks_that_do_not_already_exist()
2322
{
2423
$this->commandTester->execute([]);
@@ -28,9 +27,7 @@ public function it_adds_hooks_that_do_not_already_exist()
2827
}
2928
}
3029

31-
/**
32-
* @test
33-
*/
30+
#[Test]
3431
public function it_doesnt_allow_to_add_custom_hooks_by_default()
3532
{
3633
$customHooks = [
@@ -47,9 +44,7 @@ public function it_doesnt_allow_to_add_custom_hooks_by_default()
4744
);
4845
}
4946

50-
/**
51-
* @test
52-
*/
47+
#[Test]
5348
public function it_allows_to_add_custom_hooks_specified_in_config_section()
5449
{
5550
$customHooks = [
@@ -74,9 +69,7 @@ public function it_allows_to_add_custom_hooks_specified_in_config_section()
7469
);
7570
}
7671

77-
/**
78-
* @test
79-
*/
72+
#[Test]
8073
public function it_adds_shebang_to_hooks_on_windows()
8174
{
8275
if (! is_windows()) {
@@ -94,9 +87,7 @@ public function it_adds_shebang_to_hooks_on_windows()
9487
}
9588
}
9689

97-
/**
98-
* @test
99-
*/
90+
#[Test]
10091
public function it_does_not_add_hooks_that_already_exist()
10192
{
10293
self::createHooks();
@@ -109,9 +100,7 @@ public function it_does_not_add_hooks_that_already_exist()
109100
$this->assertStringContainsString('No hooks were added. Try updating', $this->commandTester->getDisplay());
110101
}
111102

112-
/**
113-
* @test
114-
*/
103+
#[Test]
115104
public function it_detects_existing_correct_hooks()
116105
{
117106
$originalHooks = self::$hooks;
@@ -131,9 +120,7 @@ public function it_detects_existing_correct_hooks()
131120
self::$hooks = $originalHooks;
132121
}
133122

134-
/**
135-
* @test
136-
*/
123+
#[Test]
137124
public function it_overrides_hooks_that_already_exist()
138125
{
139126
self::createHooks();
@@ -144,9 +131,7 @@ public function it_overrides_hooks_that_already_exist()
144131
}
145132
}
146133

147-
/**
148-
* @test
149-
*/
134+
#[Test]
150135
public function it_correctly_creates_the_hook_lock_file()
151136
{
152137
$currentDir = realpath(getcwd());
@@ -178,9 +163,7 @@ public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
178163
self::rmdir('../' . $lockDir);
179164
}
180165

181-
/**
182-
* @test
183-
*/
166+
#[Test]
184167
public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_passed()
185168
{
186169
$currentDir = realpath(getcwd());
@@ -190,9 +173,7 @@ public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_p
190173
$this->assertFileDoesNotExist(Hook::LOCK_FILE);
191174
}
192175

193-
/**
194-
* @test
195-
*/
176+
#[Test]
196177
public function it_does_not_ignore_the_hook_lock_file()
197178
{
198179
$currentDir = realpath(getcwd());
@@ -202,9 +183,7 @@ public function it_does_not_ignore_the_hook_lock_file()
202183
$this->assertFalse(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE));
203184
}
204185

205-
/**
206-
* @test
207-
*/
186+
#[Test]
208187
public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passed()
209188
{
210189
$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
213192
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
214193
}
215194

216-
/**
217-
* @test
218-
*/
195+
#[Test]
219196
public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
220197
{
221198
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()
225202
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
226203
}
227204

228-
/**
229-
* @test
230-
*/
205+
#[Test]
231206
public function it_uses_a_different_git_path_if_specified()
232207
{
233208
$gitDir = 'test-git-dir';
@@ -242,9 +217,7 @@ public function it_uses_a_different_git_path_if_specified()
242217
}
243218
}
244219

245-
/**
246-
* @test
247-
*/
220+
#[Test]
248221
public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
249222
{
250223
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()
256229
}
257230
}
258231

259-
/**
260-
* @test
261-
*/
232+
#[Test]
262233
public function it_create_git_hooks_path_when_hooks_dir_not_exists()
263234
{
264235
$gitDir = 'test-git-dir';
@@ -272,9 +243,7 @@ public function it_create_git_hooks_path_when_hooks_dir_not_exists()
272243
}
273244
}
274245

275-
/**
276-
* @test
277-
*/
246+
#[Test]
278247
public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
279248
{
280249
$this->commandTester->execute(['--force-win' => true]);
@@ -288,9 +257,7 @@ public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
288257
}
289258
}
290259

291-
/**
292-
* @test
293-
*/
260+
#[Test]
294261
public function it_handles_commands_defined_in_an_array()
295262
{
296263
$hooks = [
@@ -313,9 +280,7 @@ public function it_handles_commands_defined_in_an_array()
313280
}
314281

315282

316-
/**
317-
* @test
318-
*/
283+
#[Test]
319284
public function it_uses_commands_sequence_for_configured_hooks_only()
320285
{
321286
$hooks = [
@@ -350,9 +315,7 @@ public function it_uses_commands_sequence_for_configured_hooks_only()
350315
$this->assertStringContainsString($expected, $content);
351316
}
352317

353-
/**
354-
* @test
355-
*/
318+
#[Test]
356319
public function it_adds_global_git_hooks()
357320
{
358321
$gitDir = 'test-global-git-dir';
@@ -379,9 +342,7 @@ public function it_adds_global_git_hooks()
379342
$this->assertEquals($hookDir, global_hook_dir());
380343
}
381344

382-
/**
383-
* @test
384-
*/
345+
#[Test]
385346
public function it_adds_global_git_hooks_and_shows_previous_global_dir()
386347
{
387348
$gitDir = 'test-global-git-dir';
@@ -410,9 +371,7 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
410371
$this->assertEquals($hookDir, global_hook_dir());
411372
}
412373

413-
/**
414-
* @test
415-
*/
374+
#[Test]
416375
public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_matches_new_value()
417376
{
418377
$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
440399
$this->assertEquals($hookDir, global_hook_dir());
441400
}
442401

443-
/**
444-
* @test
445-
*/
402+
#[Test]
446403
public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided()
447404
{
448405
$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
474431
$this->assertEquals($hookDir, global_hook_dir());
475432
}
476433

477-
/**
478-
* @test
479-
*/
434+
#[Test]
480435
public function it_fails_if_global_hook_dir_is_missing()
481436
{
482437
putenv('COMPOSER_HOME=');
@@ -495,9 +450,7 @@ public function it_fails_if_global_hook_dir_is_missing()
495450
);
496451
}
497452

498-
/**
499-
* @test
500-
*/
453+
#[Test]
501454
public function it_adds_hooks_correctly_in_a_git_worktree()
502455
{
503456
$currentDir = realpath(getcwd());

tests/HelpersTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace BrainMaestro\GitHooks\Tests;
44

55
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
6+
use PHPUnit\Framework\Attributes\Test;
67

78
class HelpersTest extends PHPUnitTestCase
89
{
9-
/**
10-
* @test
11-
*/
10+
#[Test]
1211
public function it_checks_os()
1312
{
1413
$this->assertIsBool(is_windows());

tests/HookCommandTest.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
use BrainMaestro\GitHooks\Commands\HookCommand;
66
use Symfony\Component\Console\Tester\CommandTester;
7+
use PHPUnit\Framework\Attributes\Test;
78

89
class HookCommandTest extends TestCase
910
{
10-
/**
11-
* @test
12-
*/
11+
#[Test]
1312
public function it_tests_hooks_that_exist()
1413
{
1514
foreach (self::$hooks as $hook => $script) {
@@ -21,9 +20,7 @@ public function it_tests_hooks_that_exist()
2120
}
2221
}
2322

24-
/**
25-
* @test
26-
*/
23+
#[Test]
2724
public function it_terminates_if_previous_hook_fails()
2825
{
2926
$hook = [

0 commit comments

Comments
 (0)