Skip to content

Commit 1454da1

Browse files
committed
Upgrade to PHPUnit 12
1 parent 556ab3b commit 1454da1

23 files changed

+147
-165
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ name: "CI"
33
on:
44
pull_request:
55
push:
6-
branches:
7-
- '1.x'
8-
- '2.x'
9-
10-
env:
11-
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
126

137
jobs:
148
tests:
@@ -22,7 +16,9 @@ jobs:
2216
include:
2317
- php: '8.1'
2418
composer: 2.1.x
19+
phpunit: 10
2520
- php: '8.2'
21+
phpunit: 11
2622
- php: '8.3'
2723
- php: '8.4'
2824
- php: '8.5'
@@ -50,14 +46,14 @@ jobs:
5046

5147
- name: "Install dependencies"
5248
run: |
49+
if [[ -n "${{ matrix.phpunit || '' }}" ]]; then
50+
composer r --dev --no-update phpunit/phpunit:^${{ matrix.phpunit }} --ansi
51+
fi
5352
if [[ "${{ matrix.mode }}" = low-deps ]]; then
5453
composer u --prefer-lowest --prefer-stable --ansi
55-
composer u symfony/phpunit-bridge
5654
else
5755
composer u --ansi
5856
fi
5957
60-
- name: "Install PHPUnit"
61-
run: vendor/bin/simple-phpunit install
62-
63-
- run: vendor/bin/simple-phpunit
58+
- name: "Run tests"
59+
run: vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/vendor/
22
/build/
3-
.phpunit.result.cache
3+
/.phpunit.cache
44
.php_cs.cache
55
composer.lock

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"require-dev": {
1818
"composer/composer": "^2.1",
19+
"phpunit/phpunit": "^12.4",
1920
"symfony/dotenv": "^6.4|^7.4|^8.0",
2021
"symfony/filesystem": "^6.4|^7.4|^8.0",
21-
"symfony/phpunit-bridge": "^6.4|^7.4|^8.0",
2222
"symfony/process": "^6.4|^7.4|^8.0"
2323
},
2424
"conflict": {

phpunit.xml.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" colors="true" failOnNotice="true" failOnWarning="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<source ignoreIndirectDeprecations="true">
44
<include>
55
<directory>./src/</directory>
66
</include>
7-
</coverage>
7+
</source>
88
<testsuites>
99
<testsuite name="Symfony Flex Test Suite">
1010
<directory>./tests</directory>
1111
</testsuite>
1212
</testsuites>
1313
<php>
1414
<ini name="error_reporting" value="-1"/>
15-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
16-
<env name="LC_ALL" value="C"/>
1715
</php>
1816
</phpunit>

src/Configurator/DockerComposeConfigurator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd
275275
}
276276

277277
// Keep end in memory (check break line on previous line)
278-
$endAt[$node] = !$i || '' !== trim($lines[$i - 1]) ? $i : $i - 1;
278+
if (null !== $node) {
279+
$endAt[$node] = !$i || '' !== trim($lines[$i - 1]) ? $i : $i - 1;
280+
}
279281
$node = $matches[1];
280282
if (!isset($nodesLines[$node])) {
281283
$nodesLines[$node] = [];
@@ -285,7 +287,9 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd
285287
$startAt[$node] = $i + 1;
286288
}
287289
}
288-
$endAt[$node] = \count($lines) + 1;
290+
if (null !== $node) {
291+
$endAt[$node] = \count($lines) + 1;
292+
}
289293

290294
foreach ($extra as $key => $value) {
291295
if (isset($endAt[$key])) {

tests/Command/DumpEnvCommandTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Composer\Config;
1515
use Composer\Console\Application;
16+
use PHPUnit\Framework\Attributes\BackupGlobals;
17+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
1618
use PHPUnit\Framework\TestCase;
1719
use Symfony\Component\Console\Tester\CommandTester;
1820
use Symfony\Flex\Command\DumpEnvCommand;
@@ -82,9 +84,7 @@ public function testEmptyOptionMustIgnoreContent()
8284
unlink($envLocal);
8385
}
8486

85-
/**
86-
* @backupGlobals enabled
87-
*/
87+
#[BackupGlobals(true)]
8888
public function testEnvCanBeReferenced()
8989
{
9090
@mkdir(FLEX_TEST_DIR);
@@ -164,9 +164,7 @@ public function testDoesNotRequireToSpecifyEnvArgumentWhenLocalFileIsPresent()
164164
unlink($envLocalPhp);
165165
}
166166

167-
/**
168-
* @runInSeparateProcess
169-
*/
167+
#[RunInSeparateProcess]
170168
public function testLoadLocalEnvWhenTestEnvIsNotEqual()
171169
{
172170
@mkdir(FLEX_TEST_DIR);

tests/Command/UpdateRecipesCommandTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ protected function tearDown(): void
5252
$filesystem->remove(FLEX_TEST_DIR);
5353
}
5454

55-
/**
56-
* Skip 7.1, simply because there isn't a newer recipe version available
57-
* that we can easily use to assert.
58-
*
59-
* @requires PHP >= 7.2
60-
*/
6155
public function testCommandUpdatesRecipe()
6256
{
6357
@mkdir(FLEX_TEST_DIR);

tests/Configurator/AddLinesConfiguratorTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Composer\Package\Package;
1717
use Composer\Repository\InstalledRepositoryInterface;
1818
use Composer\Repository\RepositoryManager;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\TestCase;
2021
use Symfony\Component\Filesystem\Filesystem;
2122
use Symfony\Flex\Configurator\AddLinesConfigurator;
@@ -395,9 +396,7 @@ public function testLineProcessedIfRequiredPackageVersionIsRight()
395396
$actualContents);
396397
}
397398

398-
/**
399-
* @dataProvider getUnconfigureTests
400-
*/
399+
#[DataProvider('getUnconfigureTests')]
401400
public function testUnconfigure(string $originalContents, string $value, string $expectedContents)
402401
{
403402
$this->saveFile('assets/app.js', $originalContents);
@@ -434,7 +433,7 @@ public function testExpandTargetDirWhenUnconfiguring()
434433
, $actualContents);
435434
}
436435

437-
public function getUnconfigureTests()
436+
public static function getUnconfigureTests()
438437
{
439438
yield 'found_middle' => [
440439
<<<EOF
@@ -520,9 +519,7 @@ public function getUnconfigureTests()
520519
];
521520
}
522521

523-
/**
524-
* @dataProvider getUpdateTests
525-
*/
522+
#[DataProvider('getUpdateTests')]
526523
public function testUpdate(array $originalFiles, array $originalConfig, array $newConfig, array $expectedFiles)
527524
{
528525
foreach ($originalFiles as $filename => $originalContents) {
@@ -546,7 +543,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
546543
}
547544
}
548545

549-
public function getUpdateTests()
546+
public static function getUpdateTests()
550547
{
551548
$appJsOriginal = <<<EOF
552549
import * as Turbo from '@hotwired/turbo';

tests/Configurator/ComposerCommandConfiguratorTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Composer\Composer;
1515
use Composer\IO\IOInterface;
1616
use Composer\Util\Platform;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\TestCase;
1819
use Symfony\Flex\Configurator\ComposerCommandsConfigurator;
1920
use Symfony\Flex\Lock;
@@ -44,10 +45,8 @@ protected function tearDown(): void
4445
}
4546
}
4647

47-
/**
48-
* @dataProvider providerForConfigureMethod
49-
*/
50-
public function testConfigure($composerSchema, string $expectedComposerJson): void
48+
#[DataProvider('providerForConfigureMethod')]
49+
public function testConfigure($composerSchema, string $expectedComposerJson)
5150
{
5251
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
5352

@@ -132,10 +131,8 @@ public static function providerForConfigureMethod(): iterable
132131
];
133132
}
134133

135-
/**
136-
* @dataProvider providerForUnconfigureMethod
137-
*/
138-
public function testUnconfigure($composerSchema, string $expectedComposerJson): void
134+
#[DataProvider('providerForUnconfigureMethod')]
135+
public function testUnconfigure($composerSchema, string $expectedComposerJson)
139136
{
140137
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
141138

@@ -210,7 +207,7 @@ public static function providerForUnconfigureMethod(): iterable
210207
];
211208
}
212209

213-
public function testUpdate(): void
210+
public function testUpdate()
214211
{
215212
$configurator = new ComposerCommandsConfigurator(
216213
$this->createMock(Composer::class),

tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\Installer\InstallationManager;
1616
use Composer\IO\IOInterface;
1717
use Composer\Package\PackageInterface;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819
use PHPUnit\Framework\TestCase;
1920
use Symfony\Flex\Configurator\CopyFromPackageConfigurator;
2021
use Symfony\Flex\Lock;
@@ -57,9 +58,7 @@ public function testConfigureDirectory()
5758
}
5859
}
5960

60-
/**
61-
* @dataProvider providerTestConfigureDirectoryWithExistingFiles
62-
*/
61+
#[DataProvider('providerTestConfigureDirectoryWithExistingFiles')]
6362
public function testConfigureDirectoryWithExistingFiles(bool $force, string $sourceFileContent, string $existingTargetFileContent, string $expectedFinalTargetFileContent)
6463
{
6564
if (!is_dir($this->sourceDirectory)) {
@@ -93,7 +92,7 @@ public function testConfigureDirectoryWithExistingFiles(bool $force, string $sou
9392
}
9493
}
9594

96-
public function providerTestConfigureDirectoryWithExistingFiles(): array
95+
public static function providerTestConfigureDirectoryWithExistingFiles(): array
9796
{
9897
return [
9998
[true, 'NEW_CONTENT', 'OLD_CONTENT', 'NEW_CONTENT'],
@@ -166,16 +165,16 @@ protected function setUp(): void
166165

167166
$package = $this->getMockBuilder(PackageInterface::class)->getMock();
168167
$this->recipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock();
169-
$this->recipe->expects($this->exactly(1))->method('getPackage')->willReturn($package);
168+
$this->recipe->expects($this->once())->method('getPackage')->willReturn($package);
170169

171170
$installationManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
172-
$installationManager->expects($this->exactly(1))
171+
$installationManager->expects($this->once())
173172
->method('getInstallPath')
174173
->with($package)
175174
->willReturn(FLEX_TEST_DIR)
176175
;
177176
$this->composer = $this->getMockBuilder(Composer::class)->getMock();
178-
$this->composer->expects($this->exactly(1))
177+
$this->composer->expects($this->once())
179178
->method('getInstallationManager')
180179
->willReturn($installationManager)
181180
;

0 commit comments

Comments
 (0)