Skip to content

Commit f114a88

Browse files
committed
Upgrade to PHP 8.1 & PHPUnit 10
1 parent 4ae50d3 commit f114a88

23 files changed

+178
-185
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 13 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:
@@ -20,9 +14,8 @@ jobs:
2014
fail-fast: false
2115
matrix:
2216
include:
23-
- php: '8.0'
24-
composer: 2.2.x
2517
- php: '8.1'
18+
composer: 2.2.x
2619
- php: '8.2'
2720
- php: '8.3'
2821
- php: '8.4'
@@ -40,7 +33,7 @@ jobs:
4033
php-version: ${{ matrix.php }}
4134
tools: composer:${{ matrix.composer }}
4235

43-
- if: matrix.php == '8.0'
36+
- if: matrix.php == '8.1'
4437
name: "Lint PHP files"
4538
run: |
4639
find src/ -name '*.php' | xargs -n1 php -l
@@ -57,7 +50,5 @@ jobs:
5750
composer u --ansi
5851
fi
5952
60-
- name: "Install PHPUnit"
61-
run: vendor/bin/simple-phpunit install
62-
63-
- run: vendor/bin/simple-phpunit
53+
- name: "Run tests"
54+
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
],
1212
"minimum-stability": "dev",
1313
"require": {
14-
"php": ">=8.0",
14+
"php": ">=8.1",
1515
"composer-plugin-api": "^2.1"
1616
},
1717
"require-dev": {
1818
"composer/composer": "^2.1",
19+
"phpunit/phpunit": "^10.5",
1920
"symfony/dotenv": "^5.4|^6.0",
2021
"symfony/filesystem": "^5.4|^6.0",
21-
"symfony/phpunit-bridge": "^5.4|^6.0",
2222
"symfony/process": "^5.4|^6.0"
2323
},
2424
"conflict": {

phpunit.xml.dist

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="true"
4-
backupStaticAttributes="false"
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="true"
56
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
7+
failOnNotice="true"
8+
failOnWarning="true"
119
bootstrap="tests/bootstrap.php"
10+
cacheDirectory=".phpunit.cache"
1211
>
13-
<testsuites>
14-
<testsuite name="Symfony Flex Test Suite">
15-
<directory>./tests</directory>
16-
</testsuite>
17-
</testsuites>
12+
<testsuites>
13+
<testsuite name="Symfony Flex Test Suite">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
1817

19-
<php>
20-
<ini name="error_reporting" value="-1" />
21-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
22-
<env name="LC_ALL" value="C" />
23-
</php>
24-
25-
<filter>
26-
<whitelist>
27-
<directory>./src/</directory>
28-
</whitelist>
29-
</filter>
18+
<php>
19+
<ini name="error_reporting" value="-1" />
20+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
21+
</php>
3022
</phpunit>

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;
@@ -321,9 +322,7 @@ public function testLineProcessedIfRequiredPackageIsPresent()
321322
$actualContents);
322323
}
323324

324-
/**
325-
* @dataProvider getUnconfigureTests
326-
*/
325+
#[DataProvider('getUnconfigureTests')]
327326
public function testUnconfigure(string $originalContents, string $value, string $expectedContents)
328327
{
329328
$this->saveFile('assets/app.js', $originalContents);
@@ -360,7 +359,7 @@ public function testExpandTargetDirWhenUnconfiguring()
360359
, $actualContents);
361360
}
362361

363-
public function getUnconfigureTests()
362+
public static function getUnconfigureTests()
364363
{
365364
yield 'found_middle' => [
366365
<<<EOF
@@ -446,9 +445,7 @@ public function getUnconfigureTests()
446445
];
447446
}
448447

449-
/**
450-
* @dataProvider getUpdateTests
451-
*/
448+
#[DataProvider('getUpdateTests')]
452449
public function testUpdate(array $originalFiles, array $originalConfig, array $newConfig, array $expectedFiles)
453450
{
454451
foreach ($originalFiles as $filename => $originalContents) {
@@ -472,7 +469,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
472469
}
473470
}
474471

475-
public function getUpdateTests()
472+
public static function getUpdateTests()
476473
{
477474
$appJsOriginal = <<<EOF
478475
import * as Turbo from '@hotwired/turbo';

tests/Configurator/ComposerCommandConfiguratorTest.php

Lines changed: 3 additions & 6 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,9 +45,7 @@ protected function tearDown(): void
4445
}
4546
}
4647

47-
/**
48-
* @dataProvider providerForConfigureMethod
49-
*/
48+
#[DataProvider('providerForConfigureMethod')]
5049
public function testConfigure($composerSchema, string $expectedComposerJson): void
5150
{
5251
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
@@ -132,9 +131,7 @@ public static function providerForConfigureMethod(): iterable
132131
];
133132
}
134133

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

tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php

Lines changed: 4 additions & 4 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;
@@ -32,6 +33,7 @@ class CopyDirectoryFromPackageConfiguratorTest extends TestCase
3233
private $targetDirectory;
3334
private $io;
3435
private $recipe;
36+
private $composer;
3537

3638
public function testConfigureDirectory()
3739
{
@@ -56,9 +58,7 @@ public function testConfigureDirectory()
5658
}
5759
}
5860

59-
/**
60-
* @dataProvider providerTestConfigureDirectoryWithExistingFiles
61-
*/
61+
#[DataProvider('providerTestConfigureDirectoryWithExistingFiles')]
6262
public function testConfigureDirectoryWithExistingFiles(bool $force, string $sourceFileContent, string $existingTargetFileContent, string $expectedFinalTargetFileContent)
6363
{
6464
if (!is_dir($this->sourceDirectory)) {
@@ -92,7 +92,7 @@ public function testConfigureDirectoryWithExistingFiles(bool $force, string $sou
9292
}
9393
}
9494

95-
public function providerTestConfigureDirectoryWithExistingFiles(): array
95+
public static function providerTestConfigureDirectoryWithExistingFiles(): array
9696
{
9797
return [
9898
[true, 'NEW_CONTENT', 'OLD_CONTENT', 'NEW_CONTENT'],

tests/Configurator/CopyFromPackageConfiguratorTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ class CopyFromPackageConfiguratorTest extends TestCase
3131
private $targetDirectory;
3232
private $io;
3333
private $recipe;
34+
private $composer;
3435

3536
public function testNoFilesCopied()
3637
{
3738
if (!file_exists($this->targetDirectory)) {
3839
mkdir($this->targetDirectory);
3940
}
4041
file_put_contents($this->targetFile, '');
41-
$this->io->expects($this->exactly(1))->method('writeError')->with([' Copying files from package']);
42+
$this->io->expects($this->once())->method('writeError')->with([' Copying files from package']);
4243
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
4344
$this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
4445
}
@@ -55,8 +56,13 @@ public function testConfigureAndOverwriteFiles()
5556
file_put_contents($this->targetFile, '-');
5657
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
5758

58-
$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
59-
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./public/file"</>']);
59+
$expectedMessages = [
60+
' Copying files from package',
61+
' Created <fg=green>"./public/file"</>',
62+
];
63+
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
64+
$this->assertSame([array_shift($expectedMessages)], $message);
65+
});
6066
$this->io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);
6167

6268
$this->assertFileExists($this->targetFile);
@@ -88,9 +94,14 @@ public function testConfigure()
8894
file_put_contents($this->sourceFile, '');
8995
}
9096

91-
$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
92-
$this->io->expects($this->at(1))->method('writeError')->with([' Created <fg=green>"./public/"</>']);
93-
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./public/file"</>']);
97+
$expectedMessages = [
98+
' Copying files from package',
99+
' Created <fg=green>"./public/"</>',
100+
' Created <fg=green>"./public/file"</>',
101+
];
102+
$this->io->expects($this->exactly(3))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
103+
$this->assertSame([array_shift($expectedMessages)], $message);
104+
});
94105

95106
$this->assertFileDoesNotExist($this->targetFile);
96107
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
@@ -100,8 +111,13 @@ public function testConfigure()
100111

101112
public function testUnconfigure()
102113
{
103-
$this->io->expects($this->at(0))->method('writeError')->with([' Removing files from package']);
104-
$this->io->expects($this->at(1))->method('writeError')->with([' Removed <fg=green>"./public/file"</>']);
114+
$expectedMessages = [
115+
' Removing files from package',
116+
' Removed <fg=green>"./public/file"</>',
117+
];
118+
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
119+
$this->assertSame([array_shift($expectedMessages)], $message);
120+
});
105121

106122
if (!file_exists($this->targetDirectory)) {
107123
mkdir($this->targetDirectory);

0 commit comments

Comments
 (0)