Skip to content

Commit d743fbe

Browse files
committed
Allow range of phpunit and fix grep issue
1 parent c9d2707 commit d743fbe

File tree

9 files changed

+75
-16
lines changed

9 files changed

+75
-16
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/console": "^5.0|^6.0|^7.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^11",
23+
"phpunit/phpunit": "^9|^10|^11",
2424
"friendsofphp/php-cs-fixer": "^3.0",
2525
"ext-json": "*"
2626
},
@@ -57,7 +57,7 @@
5757
"pre-commit": "composer check-style",
5858
"pre-push": [
5959
"composer test",
60-
"appver=$(grep -o -E '\\d.\\d.\\d(-alpha.\\d)?' cghooks)",
60+
"appver=$(grep -o -P '\\d+\\.\\d+\\.\\d+(-alpha\\.\\d+)?' cghooks)",
6161
"tag=$(git tag | tail -n 1)",
6262
"if [ \"$tag\" != \"v$appver\" ]; then",
6363
"echo \"The most recent tag $tag does not match the application version $appver\\n\"",

phpunit.xml.dist

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Application Test Suite">
13-
<directory>./tests/</directory>
14-
</testsuite>
15-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Application Test Suite">
5+
<directory>./tests/</directory>
6+
</testsuite>
7+
</testsuites>
168
</phpunit>

tests/AddCommandTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BrainMaestro\GitHooks\Commands\AddCommand;
66
use BrainMaestro\GitHooks\Hook;
7+
use PHPUnit\Framework\Attributes\Group;
78
use Symfony\Component\Console\Tester\CommandTester;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use PHPUnit\Framework\Attributes\Test;
@@ -17,6 +18,7 @@ public function init()
1718
$this->commandTester = new CommandTester(new AddCommand());
1819
}
1920

21+
/** @test */
2022
#[Test]
2123
public function it_adds_hooks_that_do_not_already_exist()
2224
{
@@ -27,6 +29,7 @@ public function it_adds_hooks_that_do_not_already_exist()
2729
}
2830
}
2931

32+
/** @test */
3033
#[Test]
3134
public function it_doesnt_allow_to_add_custom_hooks_by_default()
3235
{
@@ -44,6 +47,7 @@ public function it_doesnt_allow_to_add_custom_hooks_by_default()
4447
);
4548
}
4649

50+
/** @test */
4751
#[Test]
4852
public function it_allows_to_add_custom_hooks_specified_in_config_section()
4953
{
@@ -69,6 +73,7 @@ public function it_allows_to_add_custom_hooks_specified_in_config_section()
6973
);
7074
}
7175

76+
/** @test */
7277
#[Test]
7378
public function it_adds_shebang_to_hooks_on_windows()
7479
{
@@ -87,6 +92,7 @@ public function it_adds_shebang_to_hooks_on_windows()
8792
}
8893
}
8994

95+
/** @test */
9096
#[Test]
9197
public function it_does_not_add_hooks_that_already_exist()
9298
{
@@ -100,6 +106,7 @@ public function it_does_not_add_hooks_that_already_exist()
100106
$this->assertStringContainsString('No hooks were added. Try updating', $this->commandTester->getDisplay());
101107
}
102108

109+
/** @test */
103110
#[Test]
104111
public function it_detects_existing_correct_hooks()
105112
{
@@ -120,6 +127,7 @@ public function it_detects_existing_correct_hooks()
120127
self::$hooks = $originalHooks;
121128
}
122129

130+
/** @test */
123131
#[Test]
124132
public function it_overrides_hooks_that_already_exist()
125133
{
@@ -131,6 +139,7 @@ public function it_overrides_hooks_that_already_exist()
131139
}
132140
}
133141

142+
/** @test */
134143
#[Test]
135144
public function it_correctly_creates_the_hook_lock_file()
136145
{
@@ -146,6 +155,8 @@ public function it_correctly_creates_the_hook_lock_file()
146155
* @test
147156
* @group lock-dir
148157
*/
158+
#[Test]
159+
#[Group('lock-dir')]
149160
public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
150161
{
151162
$lockDir = 'lock-dir';
@@ -163,6 +174,7 @@ public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
163174
self::rmdir('../' . $lockDir);
164175
}
165176

177+
/** @test */
166178
#[Test]
167179
public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_passed()
168180
{
@@ -173,6 +185,7 @@ public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_p
173185
$this->assertFileDoesNotExist(Hook::LOCK_FILE);
174186
}
175187

188+
/** @test */
176189
#[Test]
177190
public function it_does_not_ignore_the_hook_lock_file()
178191
{
@@ -183,6 +196,7 @@ public function it_does_not_ignore_the_hook_lock_file()
183196
$this->assertFalse(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE));
184197
}
185198

199+
/** @test */
186200
#[Test]
187201
public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passed()
188202
{
@@ -192,6 +206,7 @@ public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passe
192206
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
193207
}
194208

209+
/** @test */
195210
#[Test]
196211
public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
197212
{
@@ -202,6 +217,7 @@ public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
202217
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
203218
}
204219

220+
/** @test */
205221
#[Test]
206222
public function it_uses_a_different_git_path_if_specified()
207223
{
@@ -217,6 +233,7 @@ public function it_uses_a_different_git_path_if_specified()
217233
}
218234
}
219235

236+
/** @test */
220237
#[Test]
221238
public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
222239
{
@@ -229,6 +246,7 @@ public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
229246
}
230247
}
231248

249+
/** @test */
232250
#[Test]
233251
public function it_create_git_hooks_path_when_hooks_dir_not_exists()
234252
{
@@ -243,6 +261,7 @@ public function it_create_git_hooks_path_when_hooks_dir_not_exists()
243261
}
244262
}
245263

264+
/** @test */
246265
#[Test]
247266
public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
248267
{
@@ -257,6 +276,7 @@ public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
257276
}
258277
}
259278

279+
/** @test */
260280
#[Test]
261281
public function it_handles_commands_defined_in_an_array()
262282
{
@@ -280,6 +300,7 @@ public function it_handles_commands_defined_in_an_array()
280300
}
281301

282302

303+
/** @test */
283304
#[Test]
284305
public function it_uses_commands_sequence_for_configured_hooks_only()
285306
{
@@ -315,6 +336,7 @@ public function it_uses_commands_sequence_for_configured_hooks_only()
315336
$this->assertStringContainsString($expected, $content);
316337
}
317338

339+
/** @test */
318340
#[Test]
319341
public function it_adds_global_git_hooks()
320342
{
@@ -342,6 +364,7 @@ public function it_adds_global_git_hooks()
342364
$this->assertEquals($hookDir, global_hook_dir());
343365
}
344366

367+
/** @test */
345368
#[Test]
346369
public function it_adds_global_git_hooks_and_shows_previous_global_dir()
347370
{
@@ -371,6 +394,7 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
371394
$this->assertEquals($hookDir, global_hook_dir());
372395
}
373396

397+
/** @test */
374398
#[Test]
375399
public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_matches_new_value()
376400
{
@@ -399,6 +423,7 @@ public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_ma
399423
$this->assertEquals($hookDir, global_hook_dir());
400424
}
401425

426+
/** @test */
402427
#[Test]
403428
public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided()
404429
{
@@ -431,6 +456,7 @@ public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided
431456
$this->assertEquals($hookDir, global_hook_dir());
432457
}
433458

459+
/** @test */
434460
#[Test]
435461
public function it_fails_if_global_hook_dir_is_missing()
436462
{
@@ -450,6 +476,7 @@ public function it_fails_if_global_hook_dir_is_missing()
450476
);
451477
}
452478

479+
/** @test */
453480
#[Test]
454481
public function it_adds_hooks_correctly_in_a_git_worktree()
455482
{

tests/HelpersTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
class HelpersTest extends PHPUnitTestCase
99
{
10+
/** @test */
1011
#[Test]
1112
public function it_checks_os()
1213
{

tests/HookCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class HookCommandTest extends TestCase
1010
{
11+
/** @test */
1112
#[Test]
1213
public function it_tests_hooks_that_exist()
1314
{
@@ -20,6 +21,7 @@ public function it_tests_hooks_that_exist()
2021
}
2122
}
2223

24+
/** @test */
2325
#[Test]
2426
public function it_terminates_if_previous_hook_fails()
2527
{

tests/ListCommandTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function init()
1717
$this->commandTester = new CommandTester(new ListCommand());
1818
}
1919

20+
/** @test */
2021
#[Test]
2122
public function it_lists_hooks_that_exist()
2223
{
@@ -28,6 +29,7 @@ public function it_lists_hooks_that_exist()
2829
}
2930
}
3031

32+
/** @test */
3133
#[Test]
3234
public function it_lists_custom_hooks_that_exist()
3335
{
@@ -47,6 +49,7 @@ public function it_lists_custom_hooks_that_exist()
4749
$this->assertStringContainsString('pre-flow-feature-start', $this->commandTester->getDisplay());
4850
}
4951

52+
/** @test */
5053
#[Test]
5154
public function it_uses_a_different_git_path_if_specified()
5255
{
@@ -60,6 +63,7 @@ public function it_uses_a_different_git_path_if_specified()
6063
}
6164
}
6265

66+
/** @test */
6367
#[Test]
6468
public function it_lists_global_git_hooks()
6569
{

tests/RemoveCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use BrainMaestro\GitHooks\Commands\RemoveCommand;
66
use BrainMaestro\GitHooks\Hook;
7+
use PHPUnit\Framework\Attributes\Group;
78
use Symfony\Component\Console\Tester\CommandTester;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use PHPUnit\Framework\Attributes\Test;
1011

1112
/**
1213
* @group remove
1314
*/
15+
#[Group('remove')]
1416
class RemoveCommandTest extends TestCase
1517
{
1618
/** @var CommandTester */
@@ -22,6 +24,7 @@ public function init()
2224
$this->commandTester = new CommandTester(new RemoveCommand());
2325
}
2426

27+
/** @test */
2528
#[Test]
2629
public function it_removes_hooks_that_were_added()
2730
{
@@ -32,6 +35,7 @@ public function it_removes_hooks_that_were_added()
3235
}
3336
}
3437

38+
/** @test */
3539
#[Test]
3640
public function it_removes_custom_hooks_that_were_added()
3741
{
@@ -50,6 +54,7 @@ public function it_removes_custom_hooks_that_were_added()
5054
$this->assertStringContainsString("Removed pre-flow-feature-start hook", $this->commandTester->getDisplay());
5155
}
5256

57+
/** @test */
5358
#[Test]
5459
public function it_removes_removed_hooks_from_the_lock_file()
5560
{
@@ -68,6 +73,7 @@ public function it_removes_removed_hooks_from_the_lock_file()
6873
}
6974
}
7075

76+
/** @test */
7177
#[Test]
7278
public function it_removes_individual_hooks()
7379
{
@@ -77,6 +83,7 @@ public function it_removes_individual_hooks()
7783
}
7884
}
7985

86+
/** @test */
8087
#[Test]
8188
public function it_does_not_remove_hooks_not_present_in_the_lock_file()
8289
{
@@ -90,6 +97,7 @@ public function it_does_not_remove_hooks_not_present_in_the_lock_file()
9097
);
9198
}
9299

100+
/** @test */
93101
#[Test]
94102
public function it_removes_hooks_not_present_in_the_lock_file_if_forced_to()
95103
{
@@ -101,6 +109,7 @@ public function it_removes_hooks_not_present_in_the_lock_file_if_forced_to()
101109
$this->assertStringContainsString("Removed {$hook} hook", $this->commandTester->getDisplay());
102110
}
103111

112+
/** @test */
104113
#[Test]
105114
public function it_uses_a_different_git_path_if_specified()
106115
{
@@ -117,6 +126,7 @@ public function it_uses_a_different_git_path_if_specified()
117126
$this->assertTrue(self::isDirEmpty("{$gitDir}/hooks"));
118127
}
119128

129+
/** @test */
120130
#[Test]
121131
public function it_removes_global_git_hooks()
122132
{
@@ -140,6 +150,8 @@ public function it_removes_global_git_hooks()
140150
* @test
141151
* @group lock-dir
142152
*/
153+
#[Test]
154+
#[Group('lock-dir')]
143155
public function it_removes_git_hooks_with_lock_dir()
144156
{
145157
$lockDir = realpath(getcwd()) . '/../lock-dir';

0 commit comments

Comments
 (0)