diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index d4e3a0f5..2a3df391 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -3,12 +3,6 @@ name: "CI"
on:
pull_request:
push:
- branches:
- - '1.x'
- - '2.x'
-
-env:
- SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
jobs:
tests:
@@ -20,9 +14,8 @@ jobs:
fail-fast: false
matrix:
include:
- - php: '8.0'
- composer: 2.2.x
- php: '8.1'
+ composer: 2.2.x
- php: '8.2'
- php: '8.3'
- php: '8.4'
@@ -40,7 +33,7 @@ jobs:
php-version: ${{ matrix.php }}
tools: composer:${{ matrix.composer }}
- - if: matrix.php == '8.0'
+ - if: matrix.php == '8.1'
name: "Lint PHP files"
run: |
find src/ -name '*.php' | xargs -n1 php -l
@@ -57,7 +50,5 @@ jobs:
composer u --ansi
fi
- - name: "Install PHPUnit"
- run: vendor/bin/simple-phpunit install
-
- - run: vendor/bin/simple-phpunit
+ - name: "Run tests"
+ run: vendor/bin/phpunit
diff --git a/.gitignore b/.gitignore
index 3fe6fc29..ee04b8c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
/vendor/
/build/
-.phpunit.result.cache
+/.phpunit.cache
.php_cs.cache
composer.lock
diff --git a/composer.json b/composer.json
index d6b8f85a..d7a06d29 100644
--- a/composer.json
+++ b/composer.json
@@ -11,14 +11,14 @@
],
"minimum-stability": "dev",
"require": {
- "php": ">=8.0",
+ "php": ">=8.1",
"composer-plugin-api": "^2.1"
},
"require-dev": {
"composer/composer": "^2.1",
+ "phpunit/phpunit": "^10.5",
"symfony/dotenv": "^5.4|^6.0",
"symfony/filesystem": "^5.4|^6.0",
- "symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/process": "^5.4|^6.0"
},
"conflict": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 500b3db7..062cf4ee 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,30 +1,22 @@
-
-
-
- ./tests
-
-
+
+
+ ./tests
+
+
-
-
-
-
-
-
-
-
- ./src/
-
-
+
+
+
+
diff --git a/tests/Command/DumpEnvCommandTest.php b/tests/Command/DumpEnvCommandTest.php
index 8859cf8d..9000982d 100644
--- a/tests/Command/DumpEnvCommandTest.php
+++ b/tests/Command/DumpEnvCommandTest.php
@@ -13,6 +13,8 @@
use Composer\Config;
use Composer\Console\Application;
+use PHPUnit\Framework\Attributes\BackupGlobals;
+use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Flex\Command\DumpEnvCommand;
@@ -82,9 +84,7 @@ public function testEmptyOptionMustIgnoreContent()
unlink($envLocal);
}
- /**
- * @backupGlobals enabled
- */
+ #[BackupGlobals(true)]
public function testEnvCanBeReferenced()
{
@mkdir(FLEX_TEST_DIR);
@@ -164,9 +164,7 @@ public function testDoesNotRequireToSpecifyEnvArgumentWhenLocalFileIsPresent()
unlink($envLocalPhp);
}
- /**
- * @runInSeparateProcess
- */
+ #[RunInSeparateProcess]
public function testLoadLocalEnvWhenTestEnvIsNotEqual()
{
@mkdir(FLEX_TEST_DIR);
diff --git a/tests/Command/UpdateRecipesCommandTest.php b/tests/Command/UpdateRecipesCommandTest.php
index efd16f54..d4d2d29e 100644
--- a/tests/Command/UpdateRecipesCommandTest.php
+++ b/tests/Command/UpdateRecipesCommandTest.php
@@ -52,12 +52,6 @@ protected function tearDown(): void
$filesystem->remove(FLEX_TEST_DIR);
}
- /**
- * Skip 7.1, simply because there isn't a newer recipe version available
- * that we can easily use to assert.
- *
- * @requires PHP >= 7.2
- */
public function testCommandUpdatesRecipe()
{
@mkdir(FLEX_TEST_DIR);
diff --git a/tests/Configurator/AddLinesConfiguratorTest.php b/tests/Configurator/AddLinesConfiguratorTest.php
index b9cb5516..5a257bf5 100644
--- a/tests/Configurator/AddLinesConfiguratorTest.php
+++ b/tests/Configurator/AddLinesConfiguratorTest.php
@@ -16,6 +16,7 @@
use Composer\Package\Package;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Repository\RepositoryManager;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Flex\Configurator\AddLinesConfigurator;
@@ -321,9 +322,7 @@ public function testLineProcessedIfRequiredPackageIsPresent()
$actualContents);
}
- /**
- * @dataProvider getUnconfigureTests
- */
+ #[DataProvider('getUnconfigureTests')]
public function testUnconfigure(string $originalContents, string $value, string $expectedContents)
{
$this->saveFile('assets/app.js', $originalContents);
@@ -360,7 +359,7 @@ public function testExpandTargetDirWhenUnconfiguring()
, $actualContents);
}
- public function getUnconfigureTests()
+ public static function getUnconfigureTests()
{
yield 'found_middle' => [
<< $originalContents) {
@@ -472,7 +469,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
}
}
- public function getUpdateTests()
+ public static function getUpdateTests()
{
$appJsOriginal = <<sourceDirectory)) {
@@ -92,7 +92,7 @@ public function testConfigureDirectoryWithExistingFiles(bool $force, string $sou
}
}
- public function providerTestConfigureDirectoryWithExistingFiles(): array
+ public static function providerTestConfigureDirectoryWithExistingFiles(): array
{
return [
[true, 'NEW_CONTENT', 'OLD_CONTENT', 'NEW_CONTENT'],
diff --git a/tests/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Configurator/CopyFromPackageConfiguratorTest.php
index 8a5366b3..87aabfb4 100644
--- a/tests/Configurator/CopyFromPackageConfiguratorTest.php
+++ b/tests/Configurator/CopyFromPackageConfiguratorTest.php
@@ -31,6 +31,7 @@ class CopyFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
+ private $composer;
public function testNoFilesCopied()
{
@@ -38,7 +39,7 @@ public function testNoFilesCopied()
mkdir($this->targetDirectory);
}
file_put_contents($this->targetFile, '');
- $this->io->expects($this->exactly(1))->method('writeError')->with([' Copying files from package']);
+ $this->io->expects($this->once())->method('writeError')->with([' Copying files from package']);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
}
@@ -55,8 +56,13 @@ public function testConfigureAndOverwriteFiles()
file_put_contents($this->targetFile, '-');
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
- $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
- $this->io->expects($this->at(2))->method('writeError')->with([' Created "./public/file">']);
+ $expectedMessages = [
+ ' Copying files from package',
+ ' Created "./public/file">',
+ ];
+ $this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
$this->io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);
$this->assertFileExists($this->targetFile);
@@ -88,9 +94,14 @@ public function testConfigure()
file_put_contents($this->sourceFile, '');
}
- $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
- $this->io->expects($this->at(1))->method('writeError')->with([' Created "./public/">']);
- $this->io->expects($this->at(2))->method('writeError')->with([' Created "./public/file">']);
+ $expectedMessages = [
+ ' Copying files from package',
+ ' Created "./public/">',
+ ' Created "./public/file">',
+ ];
+ $this->io->expects($this->exactly(3))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
@@ -100,8 +111,13 @@ public function testConfigure()
public function testUnconfigure()
{
- $this->io->expects($this->at(0))->method('writeError')->with([' Removing files from package']);
- $this->io->expects($this->at(1))->method('writeError')->with([' Removed "./public/file">']);
+ $expectedMessages = [
+ ' Removing files from package',
+ ' Removed "./public/file">',
+ ];
+ $this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
if (!file_exists($this->targetDirectory)) {
mkdir($this->targetDirectory);
diff --git a/tests/Configurator/CopyFromRecipeConfiguratorTest.php b/tests/Configurator/CopyFromRecipeConfiguratorTest.php
index 2d6ba3c5..b8747acf 100644
--- a/tests/Configurator/CopyFromRecipeConfiguratorTest.php
+++ b/tests/Configurator/CopyFromRecipeConfiguratorTest.php
@@ -66,8 +66,13 @@ public function testConfigureAndOverwriteFiles()
file_put_contents($this->targetFile, '-');
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
- $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']);
- $this->io->expects($this->at(2))->method('writeError')->with([' Created "./config/file">']);
+ $expectedMessages = [
+ ' Copying files from recipe',
+ ' Created "./config/file">',
+ ];
+ $this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
$this->io->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);
$this->assertFileExists($this->targetFile);
@@ -83,8 +88,13 @@ public function testConfigureAndOverwriteFiles()
public function testConfigure()
{
- $this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']);
- $this->io->expects($this->at(1))->method('writeError')->with([' Created "./config/file">']);
+ $expectedMessages = [
+ ' Copying files from recipe',
+ ' Created "./config/file">',
+ ];
+ $this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
@@ -119,8 +129,13 @@ public function testUnconfigureKeepsLockedFiles()
public function testUnconfigure()
{
- $this->io->expects($this->at(0))->method('writeError')->with([' Removing files from recipe']);
- $this->io->expects($this->at(1))->method('writeError')->with([' Removed "./config/file">']);
+ $expectedMessages = [
+ ' Removing files from recipe',
+ ' Removed "./config/file">',
+ ];
+ $this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
+ $this->assertSame([array_shift($expectedMessages)], $message);
+ });
if (!file_exists($this->targetDirectory)) {
@mkdir($this->targetDirectory, 0777, true);
diff --git a/tests/Configurator/DockerComposeConfiguratorTest.php b/tests/Configurator/DockerComposeConfiguratorTest.php
index ec3bedd9..d60940d4 100644
--- a/tests/Configurator/DockerComposeConfiguratorTest.php
+++ b/tests/Configurator/DockerComposeConfiguratorTest.php
@@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Package\RootPackage;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Flex\Configurator\DockerComposeConfigurator;
@@ -185,9 +186,7 @@ public static function dockerComposerFileProvider(): iterable
yield ['docker-compose.yml'];
}
- /**
- * @dataProvider dockerComposerFileProvider
- */
+ #[DataProvider('dockerComposerFileProvider')]
public function testConfigure(string $fileName)
{
$dockerComposeFile = FLEX_TEST_DIR."/$fileName";
@@ -232,9 +231,7 @@ public function testNotConfiguredIfConfigSet()
$this->assertFileDoesNotExist(FLEX_TEST_DIR.'/docker-compose.yaml');
}
- /**
- * @dataProvider getInteractiveDockerPreferenceTests
- */
+ #[DataProvider('getInteractiveDockerPreferenceTests')]
public function testPreferenceAskedInteractively(string $userInput, bool $expectedIsConfigured, bool $expectedIsComposerJsonUpdated)
{
$composerJsonPath = FLEX_TEST_DIR.'/composer.json';
@@ -262,7 +259,7 @@ public function testPreferenceAskedInteractively(string $userInput, bool $expect
}
}
- public function getInteractiveDockerPreferenceTests()
+ public static function getInteractiveDockerPreferenceTests()
{
yield 'yes_once' => ['y', true, false];
yield 'no_once' => ['n', false, false];
diff --git a/tests/FlexTest.php b/tests/FlexTest.php
index 1bba9deb..ed02081a 100644
--- a/tests/FlexTest.php
+++ b/tests/FlexTest.php
@@ -32,6 +32,7 @@
use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Util\HttpDownloader;
use Composer\Util\Loop;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Flex\Configurator;
@@ -124,9 +125,7 @@ public function testActivateLoadsClasses()
$this->assertTrue(class_exists(Response::class, false));
}
- /**
- * @dataProvider getPackagesForAutoDiscovery
- */
+ #[DataProvider('getPackagesForAutoDiscovery')]
public function testBundlesAutoDiscovery(Package $package, array $expectedManifest)
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
@@ -144,7 +143,7 @@ public function testBundlesAutoDiscovery(Package $package, array $expectedManife
$flex->install($this->mockFlexEvent());
}
- public function getPackagesForAutoDiscovery(): array
+ public static function getPackagesForAutoDiscovery(): array
{
$return = [];
@@ -329,9 +328,7 @@ public function testInstallWithPackageJsonToSynchronizeSkipped()
);
}
- /**
- * @dataProvider getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped
- */
+ #[DataProvider('getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped')]
public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
{
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
@@ -346,7 +343,7 @@ public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
);
}
- public function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array
+ public static function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array
{
return [
'default_behavior' => [[]],
@@ -513,8 +510,6 @@ private function mockFlexCustom(BufferIO $io, Composer $composer, Configurator $
$flex->io = $io;
$flex->configurator = $configurator;
$flex->downloader = $downloader;
- $flex->runningCommand = function () {
- };
$flex->options = new Options(['config-dir' => 'config', 'var-dir' => 'var', 'root-dir' => '.']);
$flex->lock = $lock;
diff --git a/tests/PackageFilterTest.php b/tests/PackageFilterTest.php
index 5793c6bf..18ae720e 100644
--- a/tests/PackageFilterTest.php
+++ b/tests/PackageFilterTest.php
@@ -17,18 +17,17 @@
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\PackageInterface;
use Composer\Package\RootPackage;
+use Composer\Plugin\PrePoolCreateEvent;
use Composer\Semver\Constraint\Constraint;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\RequiresMethod;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\PackageFilter;
-/**
- * @requires function \Composer\Plugin\PrePoolCreateEvent::__construct
- */
+#[RequiresMethod(PrePoolCreateEvent::class, '__construct')]
class PackageFilterTest extends TestCase
{
- /**
- * @dataProvider provideRemoveLegacyPackages
- */
+ #[DataProvider('provideRemoveLegacyPackages')]
public function testRemoveLegacyPackages(array $expected, array $packages, string $symfonyRequire, array $versions, array $lockedPackages = [])
{
$downloader = $this->getMockBuilder('Symfony\Flex\Downloader')->disableOriginalConstructor()->getMock();
@@ -87,7 +86,7 @@ private function configToPackage(array $configs)
return $packages;
}
- public function provideRemoveLegacyPackages()
+ public static function provideRemoveLegacyPackages()
{
$branchAlias = function ($versionAlias) {
return [
diff --git a/tests/PackageJsonSynchronizerTest.php b/tests/PackageJsonSynchronizerTest.php
index 702a3881..6f5788f6 100644
--- a/tests/PackageJsonSynchronizerTest.php
+++ b/tests/PackageJsonSynchronizerTest.php
@@ -326,14 +326,17 @@ public function testSynchronizeAssetMapperNewPackage()
$entrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry.js';
$secondEntrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry2.js';
+ $expectedArguments = [
+ ['symfony-cmd', 'importmap:require', ['@hotcake/foo@^1.9.0']],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry2.js', '--path='.$secondEntrypointPath, '--entrypoint']],
+ ];
$this->scriptExecutor->expects($this->exactly(4))
->method('execute')
- ->withConsecutive(
- ['symfony-cmd', 'importmap:require', ['@hotcake/foo@^1.9.0']],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry2.js', '--path='.$secondEntrypointPath, '--entrypoint']],
- );
+ ->willReturnCallback(function (...$arguments) use (&$expectedArguments) {
+ $this->assertSame(array_shift($expectedArguments), $arguments);
+ });
$this->synchronizer->synchronize([
[
@@ -407,14 +410,17 @@ public function testSynchronizeAssetMapperUpgradesPackageIfNeeded()
$entrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry.js';
$secondEntrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry2.js';
+ $expectedArguments = [
+ ['symfony-cmd', 'importmap:require', ['@hotcake/foo@^1.9.0']],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry2.js', '--path='.$secondEntrypointPath, '--entrypoint']],
+ ];
$this->scriptExecutor->expects($this->exactly(4))
->method('execute')
- ->withConsecutive(
- ['symfony-cmd', 'importmap:require', ['@hotcake/foo@^1.9.0']],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry2.js', '--path='.$secondEntrypointPath, '--entrypoint']]
- );
+ ->willReturnCallback(function (...$arguments) use (&$expectedArguments) {
+ $this->assertSame(array_shift($expectedArguments), $arguments);
+ });
$this->synchronizer->synchronize([
[
@@ -441,12 +447,15 @@ public function testSynchronizeAssetMapperSkipsUpgradeIfAlreadySatisfied()
$fileModulePath = $this->tempDir.'/vendor/symfony/new-package/assets/dist/loader.js';
$entrypointPath = $this->tempDir.'/vendor/symfony/new-package/assets/entry.js';
+ $expectedArguments = [
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
+ ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
+ ];
$this->scriptExecutor->expects($this->exactly(2))
->method('execute')
- ->withConsecutive(
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package', '--path='.$fileModulePath]],
- ['symfony-cmd', 'importmap:require', ['@symfony/new-package/entry.js', '--path='.$entrypointPath, '--entrypoint']],
- );
+ ->willReturnCallback(function (...$arguments) use (&$expectedArguments) {
+ $this->assertSame(array_shift($expectedArguments), $arguments);
+ });
$this->synchronizer->synchronize([
[
diff --git a/tests/PackageResolverTest.php b/tests/PackageResolverTest.php
index bb6507e1..9ec7135c 100644
--- a/tests/PackageResolverTest.php
+++ b/tests/PackageResolverTest.php
@@ -11,21 +11,20 @@
namespace Symfony\Flex\Tests;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Downloader;
use Symfony\Flex\PackageResolver;
class PackageResolverTest extends TestCase
{
- /**
- * @dataProvider getPackages
- */
+ #[DataProvider('getPackages')]
public function testResolve($packages, $resolved, bool $isRequire = false)
{
$this->assertEquals($resolved, $this->getResolver()->resolve($packages, $isRequire));
}
- public function getPackages()
+ public static function getPackages()
{
return [
[
@@ -73,9 +72,7 @@ public function getPackages()
];
}
- /**
- * @dataProvider getWrongPackages
- */
+ #[DataProvider('getWrongPackages')]
public function testResolveWithErrors($packages, $error)
{
$this->expectException(\UnexpectedValueException::class);
@@ -83,7 +80,7 @@ public function testResolveWithErrors($packages, $error)
$this->getResolver()->resolve($packages);
}
- public function getWrongPackages()
+ public static function getWrongPackages()
{
return [
[
diff --git a/tests/PathTest.php b/tests/PathTest.php
index 2659ba1e..baeb95a2 100644
--- a/tests/PathTest.php
+++ b/tests/PathTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Flex\Tests;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Path;
@@ -23,9 +24,7 @@ public function testConcatenateOnWindows()
$this->assertEquals('c:\\my-project/src/kernel.php', $path->concatenate(['c:\\my-project', 'src/', 'kernel.php']));
}
- /**
- * @dataProvider providePathsForConcatenation
- */
+ #[DataProvider('providePathsForConcatenation')]
public function testConcatenate($part1, $part2, $expectedPath)
{
$path = new Path('');
@@ -35,7 +34,7 @@ public function testConcatenate($part1, $part2, $expectedPath)
$this->assertEquals($expectedPath, $actualPath);
}
- public function providePathsForConcatenation()
+ public static function providePathsForConcatenation()
{
return [
[__DIR__, 'foo/bar.txt', __DIR__.'/foo/bar.txt'],
diff --git a/tests/ScriptExecutorTest.php b/tests/ScriptExecutorTest.php
index 1b641312..e29c433d 100644
--- a/tests/ScriptExecutorTest.php
+++ b/tests/ScriptExecutorTest.php
@@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\IO\NullIO;
use Composer\Util\ProcessExecutor;
+use PHPUnit\Framework\Attributes\BackupGlobals;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Flex\Options;
@@ -21,9 +22,7 @@
final class ScriptExecutorTest extends TestCase
{
- /**
- * @backupGlobals enabled
- */
+ #[BackupGlobals(true)]
public function testMemoryLimit(): void
{
$command = './command.php';
diff --git a/tests/SymfonyBundleTest.php b/tests/SymfonyBundleTest.php
index 35788fce..5af36bae 100644
--- a/tests/SymfonyBundleTest.php
+++ b/tests/SymfonyBundleTest.php
@@ -12,14 +12,13 @@
namespace Symfony\Flex\Tests;
use Composer\Package\Package;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\SymfonyBundle;
class SymfonyBundleTest extends TestCase
{
- /**
- * @dataProvider getNamespaces
- */
+ #[DataProvider('getNamespaces')]
public function testGetClassNamesForInstall($package, $autoload, $classes, $type = null)
{
$config = $this->getMockBuilder('Composer\Config')->getMock();
@@ -36,10 +35,8 @@ public function testGetClassNamesForInstall($package, $autoload, $classes, $type
$this->assertSame($classes, $bundle->getClassNames());
}
- public function getNamespaces()
+ public static function getNamespaces()
{
- $return = [];
-
$packages = FlexTest::getTestPackages();
foreach ($packages as $name => $info) {
$packageData = [$name, $info['autoload'], $info['bundles']];
@@ -47,9 +44,7 @@ public function getNamespaces()
$packageData[] = $info['type'];
}
- $return[] = $packageData;
+ yield $packageData;
}
-
- return $return;
}
}
diff --git a/tests/UnpackerTest.php b/tests/UnpackerTest.php
index 785da05a..24d99a0d 100644
--- a/tests/UnpackerTest.php
+++ b/tests/UnpackerTest.php
@@ -39,7 +39,7 @@ public function testDoNotDuplicateEntry(): void
@unlink($composerJsonPath);
file_put_contents($composerJsonPath, '{}');
- $originalEnvComposer = $_SERVER['COMPOSER'];
+ $originalEnvComposer = $_SERVER['COMPOSER'] ?? null;
$_SERVER['COMPOSER'] = $composerJsonPath;
// composer 2.1 and lower support
putenv('COMPOSER='.$composerJsonPath);
diff --git a/tests/Update/DiffHelperTest.php b/tests/Update/DiffHelperTest.php
index 3e928b59..fe13bf3d 100644
--- a/tests/Update/DiffHelperTest.php
+++ b/tests/Update/DiffHelperTest.php
@@ -11,14 +11,13 @@
namespace Symfony\Flex\Tests\Update;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Update\DiffHelper;
class DiffHelperTest extends TestCase
{
- /**
- * @dataProvider getRemoveFilesFromPatchTests
- */
+ #[DataProvider('getRemoveFilesFromPatchTests')]
public function testRemoveFilesFromPatch(string $patch, array $filesToRemove, string $expectedPatch, array $expectedRemovedPatches)
{
$removedPatches = [];
@@ -27,7 +26,7 @@ public function testRemoveFilesFromPatch(string $patch, array $filesToRemove, st
$this->assertSame($expectedRemovedPatches, $removedPatches);
}
- public function getRemoveFilesFromPatchTests(): iterable
+ public static function getRemoveFilesFromPatchTests(): iterable
{
$patch = <<getFilesystem()->remove(FLEX_TEST_DIR);
- $this->getFilesystem()->mkdir(FLEX_TEST_DIR);
+ self::getFilesystem()->remove(FLEX_TEST_DIR);
+ self::getFilesystem()->mkdir(FLEX_TEST_DIR);
}
- /**
- * @dataProvider getGeneratePatchTests
- */
+ #[DataProvider('getGeneratePatchTests')]
public function testGeneratePatch(array $originalFiles, array $newFiles, string $expectedPatch, array $expectedDeletedFiles = [])
{
- $this->getFilesystem()->remove(FLEX_TEST_DIR);
- $this->getFilesystem()->mkdir(FLEX_TEST_DIR);
+ self::getFilesystem()->remove(FLEX_TEST_DIR);
+ self::getFilesystem()->mkdir(FLEX_TEST_DIR);
// original files need to be present to avoid patcher thinking they were deleting and skipping patch
foreach ($originalFiles as $file => $contents) {
touch(FLEX_TEST_DIR.'/'.$file);
@@ -79,7 +78,7 @@ public function testGeneratePatch(array $originalFiles, array $newFiles, string
$this->assertSame($expectedBlobs, $actualShortenedBlobs);
}
- public function getGeneratePatchTests(): iterable
+ public static function getGeneratePatchTests(): iterable
{
yield 'updated_file' => [
['file1.txt' => 'Original contents', 'file2.txt' => 'Original file2'],
@@ -186,8 +185,8 @@ public function getGeneratePatchTests(): iterable
public function testGeneratePatchOnDeletedFile()
{
// make sure the target directory is empty
- $this->getFilesystem()->remove(FLEX_TEST_DIR);
- $this->getFilesystem()->mkdir(FLEX_TEST_DIR);
+ self::getFilesystem()->remove(FLEX_TEST_DIR);
+ self::getFilesystem()->mkdir(FLEX_TEST_DIR);
$patcher = new RecipePatcher(FLEX_TEST_DIR, $this->createMock(IOInterface::class));
@@ -196,9 +195,7 @@ public function testGeneratePatchOnDeletedFile()
$this->assertSame('', $patch->getPatch());
}
- /**
- * @dataProvider getApplyPatchTests
- */
+ #[DataProvider('provideApplyPatchCases')]
public function testApplyPatch(array $filesCurrentlyInApp, RecipePatch $recipePatch, array $expectedFiles, bool $expectedConflicts)
{
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
@@ -233,9 +230,12 @@ public function testApplyPatch(array $filesCurrentlyInApp, RecipePatch $recipePa
$this->assertSame($expectedConflicts, $hadConflicts);
}
- /**
- * @dataProvider getApplyPatchTests
- */
+ public static function provideApplyPatchCases(): iterable
+ {
+ yield from self::getApplyPatchTests('');
+ }
+
+ #[DataProvider('provideApplyPatchOnSubfolderCases')]
public function testApplyPatchOnSubfolder(array $filesCurrentlyInApp, RecipePatch $recipePatch, array $expectedFiles, bool $expectedConflicts)
{
$mainProjectPath = FLEX_TEST_DIR;
@@ -277,10 +277,14 @@ public function testApplyPatchOnSubfolder(array $filesCurrentlyInApp, RecipePatc
$this->assertSame($expectedConflicts, $hadConflicts);
}
- public function getApplyPatchTests(string $testMethodName): iterable
+ public static function provideApplyPatchOnSubfolderCases(): iterable
{
- $projectRootPath = ('testApplyPatchOnSubfolder' === $testMethodName) ? 'ProjectA/' : '';
- $files = $this->getFilesForPatching($projectRootPath);
+ yield from self::getApplyPatchTests('ProjectA/');
+ }
+
+ public static function getApplyPatchTests(string $projectRootPath): iterable
+ {
+ $files = self::getFilesForPatching($projectRootPath);
$dotEnvClean = $files['dot_env_clean'];
$packageJsonConflict = $files['package_json_conflict'];
$webpackEncoreAdded = $files['webpack_encore_added'];
@@ -362,12 +366,10 @@ public function getApplyPatchTests(string $testMethodName): iterable
];
}
- /**
- * @dataProvider getIntegrationTests
- */
+ #[DataProvider('getIntegrationTests')]
public function testIntegration(bool $useNullForMissingFiles)
{
- $files = $this->getFilesForPatching();
+ $files = self::getFilesForPatching();
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.name', 'Unit test'], FLEX_TEST_DIR))->mustRun();
(new Process(['git', 'config', 'user.email', ''], FLEX_TEST_DIR))->mustRun();
@@ -421,7 +423,7 @@ public function testIntegration(bool $useNullForMissingFiles)
$this->assertFileDoesNotExist(FLEX_TEST_DIR.'/security.yaml');
}
- public function getIntegrationTests(): iterable
+ public static function getIntegrationTests(): iterable
{
yield 'missing_files_set_to_null' => [true];
yield 'missing_files_not_in_array' => [false];
@@ -438,7 +440,7 @@ public function getIntegrationTests(): iterable
* * original_recipe
* * updated_recipe.
*/
- private function getFilesForPatching(string $projectPath = ''): array
+ private static function getFilesForPatching(string $projectPath = ''): array
{
$files = [
// .env
@@ -583,18 +585,18 @@ private function getFilesForPatching(string $projectPath = ''): array
foreach ($files as $key => $data) {
$files[$key] = array_merge(
$data,
- $this->generatePatchData($projectPath.$data['filename'], $data['original_recipe'], $data['updated_recipe'])
+ self::generatePatchData($projectPath.$data['filename'], $data['original_recipe'], $data['updated_recipe'])
);
}
return $files;
}
- private function generatePatchData(string $filename, ?string $start, ?string $end): array
+ private static function generatePatchData(string $filename, ?string $start, ?string $end): array
{
$dir = sys_get_temp_dir().'/_flex_diff';
if (file_exists($dir)) {
- $this->getFilesystem()->remove($dir);
+ self::getFilesystem()->remove($dir);
}
@mkdir($dir);
(new Process(['git', 'init'], $dir))->mustRun();
@@ -636,12 +638,12 @@ private function generatePatchData(string $filename, ?string $start, ?string $en
];
}
- private function getFilesystem(): Filesystem
+ private static function getFilesystem(): Filesystem
{
- if (null === $this->filesystem) {
- $this->filesystem = new Filesystem();
+ if (null === self::$filesystem) {
+ self::$filesystem = new Filesystem();
}
- return $this->filesystem;
+ return self::$filesystem;
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 3a53bc61..8aceb43a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -16,3 +16,5 @@
rmdir($buildDir);
}
+
+mkdir($buildDir);