Skip to content

Commit af25394

Browse files
Merge pull request #284 from captainhook-git/feature/upgrade-to-phpunit-10
Migrate from PHPUnit 9 to PHPUnit 10
2 parents f2278ed + 94e9d24 commit af25394

144 files changed

Lines changed: 160 additions & 2147 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/integration.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ jobs:
1212
include:
1313
- php: 8.0
1414
buildphar: false
15+
runtests: false
1516
experimental: false
1617
- php: 8.1
1718
buildphar: false
19+
runtests: true
1820
experimental: false
1921
- php: 8.2
2022
buildphar: true
23+
runtests: true
2124
experimental: false
2225
- php: 8.3
2326
buildphar: true
27+
runtests: true
2428
experimental: false
2529
- php: 8.4
2630
buildphar: true
27-
experimental: true
31+
runtests: false
32+
experimental: false
2833
env:
2934
PHAR: build/phar/captainhook.phar
3035

@@ -54,12 +59,15 @@ jobs:
5459
run: GITHUB_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} tools/phive --no-progress --home ./.phive install --force-accept-unsigned --trust-gpg-keys 4AA394086372C20A,31C7E470E2138192,8E730BA25823D8B5,CF1A108D0E7AE720,2DF45277AEF09A2F,51C67305FFC2E5C0
5560

5661
- name: Execute unit tests
62+
if: ${{ matrix.runtests }}
5763
run: tools/phpunit --no-coverage --testsuite UnitTests
5864

5965
- name: Execute integration tests
66+
if: ${{ matrix.runtests }}
6067
run: tools/phpunit --no-coverage --testsuite IntegrationTests
6168

6269
- name: Execute end-to-end tests
70+
if: ${{ matrix.runtests }}
6371
run: tools/phpunit --no-coverage --testsuite EndToEndTests
6472

6573
- name: Execute dummy pre commit

phive.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpunit" version="^9.4" installed="9.6.23" location="./tools/phpunit" copy="true"/>
4-
<phar name="humbug/box" version="^4.0" installed="4.6.6" location="./tools/box" copy="true"/>
3+
<phar name="phpunit" version="^10.0" installed="10.5.58" location="./tools/phpunit" copy="true"/>
4+
<phar name="humbug/box" version="^4.0" installed="4.6.8" location="./tools/box" copy="true"/>
55
<phar name="phpcs" version="^3.5" installed="3.7.2" location="./tools/phpcs" copy="true"/>
6-
<phar name="phpstan" version="^1.0" installed="1.12.28" location="./tools/phpstan" copy="true"/>
6+
<phar name="phpstan" version="^1.0" installed="1.12.32" location="./tools/phpstan" copy="true"/>
77
</phive>

phpunit.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
43
colors="true"
54
bootstrap="tests/bootstrap.php"
6-
defaultTestSuite="UnitTests">
5+
defaultTestSuite="UnitTests"
6+
displayDetailsOnPhpunitDeprecations="true"
7+
displayDetailsOnTestsThatTriggerDeprecations="true"
8+
displayDetailsOnTestsThatTriggerWarnings="true">
79
<coverage>
8-
<include>
9-
<directory>src</directory>
10-
</include>
1110
<report>
1211
<clover outputFile="build/logs/clover.xml"/>
1312
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
@@ -27,4 +26,9 @@
2726
<logging>
2827
<junit outputFile="build/logs/junit.xml"/>
2928
</logging>
29+
<source>
30+
<include>
31+
<directory>src</directory>
32+
</include>
33+
</source>
3034
</phpunit>

src/Config/Factory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ private function loadConfigFromFile(Json $file, array $settings): Config
138138

139139
$this->appendIncludedConfigurations($config, $json);
140140

141+
// fallback to $json->HOOK_NAME if $json->HOOKS->HOOK_NAME does not exist
142+
$hooks = $json['hooks'] ?? $json;
143+
141144
foreach (HookUtil::getValidHooks() as $hook => $class) {
142-
if (isset($json[$hook])) {
143-
$this->configureHook($config->getHookConfig($hook), $json[$hook]);
145+
if (isset($hooks[$hook])) {
146+
$this->configureHook($config->getHookConfig($hook), $hooks[$hook]);
144147
}
145148
}
146149

tests/_files/bootstrap/crash.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
22

3-
require 'foo.txt';
3+
// I know ugly but I want this to crash
4+
@require 'foo.txt';

tests/unit/Config/ConditionTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@
1515

1616
class ConditionTest extends TestCase
1717
{
18-
/**
19-
* Tests Condition::getExec
20-
*/
2118
public function testGetExec(): void
2219
{
2320
$config = new Condition('\\Foo\\Bar');
2421

2522
$this->assertEquals('\\Foo\\Bar', $config->getExec());
2623
}
2724

28-
/**
29-
* Tests Condition::getArgs
30-
*/
3125
public function testGetEmptyArgs(): void
3226
{
3327
$config = new Condition('\\Foo\\Bar');

tests/unit/Config/FactoryTest.php

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
class FactoryTest extends TestCase
1818
{
19-
/**
20-
* Tests Factory::create
21-
*
22-
* @throws \Exception
23-
*/
2419
public function testCreate(): void
2520
{
2621
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid.json'));
@@ -29,23 +24,13 @@ public function testCreate(): void
2924
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
3025
}
3126

32-
/**
33-
* Tests Factory::create
34-
*
35-
* @throws \Exception
36-
*/
3727
public function testOverwriteConfigSettingsBySettingsConfigFile(): void
3828
{
3929
$config = Factory::create(realpath(CH_PATH_FILES . '/config/config-file/captainhook.json'));
4030

4131
$this->assertEquals('quiet', $config->getVerbosity());
4232
}
4333

44-
/**
45-
* Tests Factory::create
46-
*
47-
* @throws \Exception
48-
*/
4934
public function testCreateWithAbsoluteGitDir(): void
5035
{
5136
$config = Factory::create(
@@ -58,11 +43,6 @@ public function testCreateWithAbsoluteGitDir(): void
5843
$this->assertEquals('/foo', $config->getGitDirectory());
5944
}
6045

61-
/**
62-
* Tests Factory::create
63-
*
64-
* @throws \Exception
65-
*/
6646
public function testCreateWithInvalidPhpPath(): void
6747
{
6848
$this->expectException(Exception::class);
@@ -73,11 +53,6 @@ public function testCreateWithInvalidPhpPath(): void
7353
);
7454
}
7555

76-
/**
77-
* Tests Factory::create
78-
*
79-
* @throws \Exception
80-
*/
8156
public function testCreateWithRelativeGitDir(): void
8257
{
8358
$path = realpath(CH_PATH_FILES . '/config/valid.json');
@@ -88,9 +63,6 @@ public function testCreateWithRelativeGitDir(): void
8863
$this->assertEquals(dirname($path) . DIRECTORY_SEPARATOR . '../.git', $config->getGitDirectory());
8964
}
9065

91-
/**
92-
* Tests Factory::create
93-
*/
9466
public function testCreateWithRunConfig(): void
9567
{
9668
$path = realpath(CH_PATH_FILES . '/config/valid-run-config-nested.json');
@@ -101,9 +73,6 @@ public function testCreateWithRunConfig(): void
10173
$this->assertEquals('/docker/.git', $config->getRunConfig()->getGitPath());
10274
}
10375

104-
/**
105-
* Tests Factory::create
106-
*/
10776
public function testCreateWithRunConfigLegacy(): void
10877
{
10978
$path = realpath(CH_PATH_FILES . '/config/valid-run-config-legacy.json');
@@ -114,11 +83,6 @@ public function testCreateWithRunConfigLegacy(): void
11483
$this->assertEquals('/docker/.git', $config->getRunConfig()->getGitPath());
11584
}
11685

117-
/**
118-
* Tests Factory::create
119-
*
120-
* @throws \Exception
121-
*/
12286
public function testCreateWithConditions(): void
12387
{
12488
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-conditions.json'));
@@ -127,35 +91,20 @@ public function testCreateWithConditions(): void
12791
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
12892
}
12993

130-
/**
131-
* Tests Factory::create
132-
*
133-
* @throws \Exception
134-
*/
13594
public function testCreateWithSettings(): void
13695
{
13796
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-conditions.json'));
13897

13998
$this->assertTrue($config->getHookConfig('pre-commit')->getActions()[0]->isFailureAllowed());
14099
}
141100

142-
/**
143-
* Tests Factory::create
144-
*
145-
* @throws \Exception
146-
*/
147101
public function testCreateWithCrazyPHPPath(): void
148102
{
149103
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-strange-settings.json'));
150104

151105
$this->assertEquals("tests/_files/bin/success foo", $config->getPhpPath());
152106
}
153107

154-
/**
155-
* Tests Factory::create
156-
*
157-
* @throws \Exception
158-
*/
159108
public function testCreateWithAllSetting(): void
160109
{
161110
$path = realpath(CH_PATH_FILES . '/config/valid-with-all-settings.json');
@@ -172,11 +121,6 @@ public function testCreateWithAllSetting(): void
172121
$this->assertEquals(false, $config->failOnFirstError());
173122
}
174123

175-
/**
176-
* Tests Factory::create
177-
*
178-
* @throws \Exception
179-
*/
180124
public function testCreateWithIncludes(): void
181125
{
182126
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-includes.json'));
@@ -185,11 +129,6 @@ public function testCreateWithIncludes(): void
185129
$this->assertCount(2, $config->getHookConfig('pre-commit')->getActions());
186130
}
187131

188-
/**
189-
* Tests Factory::create
190-
*
191-
* @throws \Exception
192-
*/
193132
public function testCreateWithValidNestedIncludes(): void
194133
{
195134
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-nested-includes.json'));
@@ -200,11 +139,6 @@ public function testCreateWithValidNestedIncludes(): void
200139
$this->assertCount(2, $config->getHookConfig('pre-push')->getActions());
201140
}
202141

203-
/**
204-
* Tests Factory::create
205-
*
206-
* @throws \Exception
207-
*/
208142
public function testCreateWithInvalidNestedIncludes(): void
209143
{
210144
$config = Factory::create(realpath(CH_PATH_FILES . '/config/invalid-with-nested-includes.json'));
@@ -213,22 +147,12 @@ public function testCreateWithInvalidNestedIncludes(): void
213147
$this->assertCount(2, $config->getHookConfig('pre-commit')->getActions());
214148
}
215149

216-
/**
217-
* Tests Factory::create
218-
*
219-
* @throws \Exception
220-
*/
221150
public function testCreateWithInvalidIncludes(): void
222151
{
223152
$this->expectException(Exception::class);
224153
Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-invalid-includes.json'));
225154
}
226155

227-
/**
228-
* Tests Factory::create
229-
*
230-
* @throws \Exception
231-
*/
232156
public function testCreateEmptyWithIncludes(): void
233157
{
234158
$config = Factory::create(realpath(CH_PATH_FILES . '/config/empty-with-includes.json'));
@@ -237,11 +161,6 @@ public function testCreateEmptyWithIncludes(): void
237161
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
238162
}
239163

240-
/**
241-
* Tests Factory::create
242-
*
243-
* @throws \Exception
244-
*/
245164
public function testCreateWithNestedAndConditions(): void
246165
{
247166
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-nested-and-conditions.json'));
@@ -250,23 +169,13 @@ public function testCreateWithNestedAndConditions(): void
250169
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
251170
}
252171

253-
/**
254-
* Tests Factory::create
255-
*
256-
* @throws \Exception
257-
*/
258172
public function testWithMainConfigurationOverridingInclude(): void
259173
{
260174
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-disabled-action.json'));
261175

262176
$this->assertFalse($config->getHookConfig('pre-commit')->isEnabled());
263177
}
264178

265-
/**
266-
* Tests Factory::create
267-
*
268-
* @throws \Exception
269-
*/
270179
public function testMaxIncludeLevel(): void
271180
{
272181
// one of the included files will not be loaded because of the includes-level value of 2

tests/unit/Config/HookTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
class HookTest extends TestCase
1717
{
18-
/**
19-
* Tests Hook::__construct
20-
*/
2118
public function testDisabledByDefault(): void
2219
{
2320
$hook = new Hook('pre-commit');
@@ -27,9 +24,6 @@ public function testDisabledByDefault(): void
2724
$this->assertFalse($config['enabled']);
2825
}
2926

30-
/**
31-
* Tests Hook::setEnabled
32-
*/
3327
public function testSetEnabled(): void
3428
{
3529
$hook = new Hook('pre-commit');
@@ -40,9 +34,6 @@ public function testSetEnabled(): void
4034
$this->assertTrue($config['enabled']);
4135
}
4236

43-
/**
44-
* Tests Hook::__construct
45-
*/
4637
public function testEmptyActions(): void
4738
{
4839
$hook = new Hook('pre-commit');
@@ -52,9 +43,6 @@ public function testEmptyActions(): void
5243
$this->assertCount(0, $config['actions']);
5344
}
5445

55-
/**
56-
* Tests Hook::addAction
57-
*/
5846
public function testAddAction(): void
5947
{
6048
$hook = new Hook('pre-commit');
@@ -65,9 +53,6 @@ public function testAddAction(): void
6553
$this->assertCount(1, $config['actions']);
6654
}
6755

68-
/**
69-
* Tests Hook::addAction
70-
*/
7156
public function testAddMultiAction(): void
7257
{
7358
$hook = new Hook('pre-commit');

0 commit comments

Comments
 (0)