Skip to content

Upgrade to PHP 8.1 & PHPUnit 10 #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor/
/build/
.phpunit.result.cache
/.phpunit.cache
.php_cs.cache
composer.lock
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": {
38 changes: 15 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="true"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
failOnNotice="true"
failOnWarning="true"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Symfony Flex Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Symfony Flex Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<env name="LC_ALL" value="C" />
</php>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
</phpunit>
10 changes: 4 additions & 6 deletions tests/Command/DumpEnvCommandTest.php
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 0 additions & 6 deletions tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 5 additions & 8 deletions tests/Configurator/AddLinesConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -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' => [
<<<EOF
@@ -446,9 +445,7 @@ public function getUnconfigureTests()
];
}

/**
* @dataProvider getUpdateTests
*/
#[DataProvider('getUpdateTests')]
public function testUpdate(array $originalFiles, array $originalConfig, array $newConfig, array $expectedFiles)
{
foreach ($originalFiles as $filename => $originalContents) {
@@ -472,7 +469,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
}
}

public function getUpdateTests()
public static function getUpdateTests()
{
$appJsOriginal = <<<EOF
import * as Turbo from '@hotwired/turbo';
9 changes: 3 additions & 6 deletions tests/Configurator/ComposerCommandConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Util\Platform;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Configurator\ComposerCommandsConfigurator;
use Symfony\Flex\Lock;
@@ -44,9 +45,7 @@ protected function tearDown(): void
}
}

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

/**
* @dataProvider providerForUnconfigureMethod
*/
#[DataProvider('providerForUnconfigureMethod')]
public function testUnconfigure($composerSchema, string $expectedComposerJson): void
{
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use Composer\Installer\InstallationManager;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Configurator\CopyFromPackageConfigurator;
use Symfony\Flex\Lock;
@@ -32,6 +33,7 @@ class CopyDirectoryFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testConfigureDirectory()
{
@@ -56,9 +58,7 @@ public function testConfigureDirectory()
}
}

/**
* @dataProvider providerTestConfigureDirectoryWithExistingFiles
*/
#[DataProvider('providerTestConfigureDirectoryWithExistingFiles')]
public function testConfigureDirectoryWithExistingFiles(bool $force, string $sourceFileContent, string $existingTargetFileContent, string $expectedFinalTargetFileContent)
{
if (!is_dir($this->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'],
32 changes: 24 additions & 8 deletions tests/Configurator/CopyFromPackageConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -31,14 +31,15 @@ class CopyFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testNoFilesCopied()
{
if (!file_exists($this->targetDirectory)) {
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 <fg=green>"./public/file"</>']);
$expectedMessages = [
' Copying files from package',
' Created <fg=green>"./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 <fg=green>"./public/"</>']);
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./public/file"</>']);
$expectedMessages = [
' Copying files from package',
' Created <fg=green>"./public/"</>',
' Created <fg=green>"./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 <fg=green>"./public/file"</>']);
$expectedMessages = [
' Removing files from package',
' Removed <fg=green>"./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);
27 changes: 21 additions & 6 deletions tests/Configurator/CopyFromRecipeConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -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 <fg=green>"./config/file"</>']);
$expectedMessages = [
' Copying files from recipe',
' Created <fg=green>"./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 <fg=green>"./config/file"</>']);
$expectedMessages = [
' Copying files from recipe',
' Created <fg=green>"./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 <fg=green>"./config/file"</>']);
$expectedMessages = [
' Removing files from recipe',
' Removed <fg=green>"./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);
11 changes: 4 additions & 7 deletions tests/Configurator/DockerComposeConfiguratorTest.php
Original file line number Diff line number Diff line change
@@ -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];
15 changes: 5 additions & 10 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
@@ -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;

13 changes: 6 additions & 7 deletions tests/PackageFilterTest.php
Original file line number Diff line number Diff line change
@@ -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 [
41 changes: 25 additions & 16 deletions tests/PackageJsonSynchronizerTest.php
Original file line number Diff line number Diff line change
@@ -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([
[
13 changes: 5 additions & 8 deletions tests/PackageResolverTest.php
Original file line number Diff line number Diff line change
@@ -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,17 +72,15 @@ public function getPackages()
];
}

/**
* @dataProvider getWrongPackages
*/
#[DataProvider('getWrongPackages')]
public function testResolveWithErrors($packages, $error)
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage($error);
$this->getResolver()->resolve($packages);
}

public function getWrongPackages()
public static function getWrongPackages()
{
return [
[
7 changes: 3 additions & 4 deletions tests/PathTest.php
Original file line number Diff line number Diff line change
@@ -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'],
5 changes: 2 additions & 3 deletions tests/ScriptExecutorTest.php
Original file line number Diff line number Diff line change
@@ -14,16 +14,15 @@
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;
use Symfony\Flex\ScriptExecutor;

final class ScriptExecutorTest extends TestCase
{
/**
* @backupGlobals enabled
*/
#[BackupGlobals(true)]
public function testMemoryLimit(): void
{
$command = './command.php';
13 changes: 4 additions & 9 deletions tests/SymfonyBundleTest.php
Original file line number Diff line number Diff line change
@@ -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,20 +35,16 @@ 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']];
if (isset($info['type'])) {
$packageData[] = $info['type'];
}

$return[] = $packageData;
yield $packageData;
}

return $return;
}
}
2 changes: 1 addition & 1 deletion tests/UnpackerTest.php
Original file line number Diff line number Diff line change
@@ -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);
7 changes: 3 additions & 4 deletions tests/Update/DiffHelperTest.php
Original file line number Diff line number Diff line change
@@ -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 = <<<EOF
diff --git a/.env b/.env
68 changes: 35 additions & 33 deletions tests/Update/RecipePatcherTest.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
namespace Symfony\Flex\Tests\Update;

use Composer\IO\IOInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
@@ -20,21 +21,19 @@

class RecipePatcherTest extends TestCase
{
private $filesystem;
private static $filesystem;

protected function setUp(): void
{
$this->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;
}
}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -16,3 +16,5 @@

rmdir($buildDir);
}

mkdir($buildDir);