From 3319fcf700239ecd28c30edce7504da45c26ff8d Mon Sep 17 00:00:00 2001 From: HypeMC Date: Thu, 29 May 2025 20:02:14 +0200 Subject: [PATCH 1/5] Add option to specify version in add lines requires --- src/Configurator/AddLinesConfigurator.php | 8 +- .../Configurator/AddLinesConfiguratorTest.php | 83 ++++++++++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/Configurator/AddLinesConfigurator.php b/src/Configurator/AddLinesConfigurator.php index 8a4bc6d62..40cc751a1 100644 --- a/src/Configurator/AddLinesConfigurator.php +++ b/src/Configurator/AddLinesConfigurator.php @@ -237,8 +237,12 @@ private function isPackageInstalled($packages): bool $installedRepo = $this->composer->getRepositoryManager()->getLocalRepository(); - foreach ($packages as $packageName) { - if (null === $installedRepo->findPackage($packageName, '*')) { + foreach ($packages as $package) { + $package = explode(':', $package, 2); + $packageName = $package[0]; + $constraint = $package[1] ?? '*'; + + if (null === $installedRepo->findPackage($packageName, $constraint)) { return false; } } diff --git a/tests/Configurator/AddLinesConfiguratorTest.php b/tests/Configurator/AddLinesConfiguratorTest.php index 43306947e..2ce1cfb9e 100644 --- a/tests/Configurator/AddLinesConfiguratorTest.php +++ b/tests/Configurator/AddLinesConfiguratorTest.php @@ -321,6 +321,80 @@ public function testLineProcessedIfRequiredPackageIsPresent() $actualContents); } + public function testLineSkippedIfRequiredPackageVersionIsWrong() + { + $this->saveFile('phpunit.dist.xml', << + + + + +EOF + ); + + $composer = $this->createComposerMockWithPackagesInstalled([ + 'phpunit/phpunit:9', + ]); + + $this->runConfigure([ + [ + 'file' => 'phpunit.dist.xml', + 'position' => 'after_target', + 'target' => '', + 'content' => ' ', + 'requires' => 'phpunit/phpunit:12', + ], + ], $composer); + $actualContents = $this->readFile('phpunit.dist.xml'); + $this->assertSame(<< + + + + +EOF + , + $actualContents); + } + + public function testLineProcessedIfRequiredPackageVersionIsRight() + { + $this->saveFile('phpunit.dist.xml', << + + + + +EOF + ); + + $composer = $this->createComposerMockWithPackagesInstalled([ + 'phpunit/phpunit:12', + ]); + + $this->runConfigure([ + [ + 'file' => 'phpunit.dist.xml', + 'position' => 'after_target', + 'target' => '', + 'content' => ' ', + 'requires' => 'phpunit/phpunit:12', + ], + ], $composer); + + $actualContents = $this->readFile('phpunit.dist.xml'); + $this->assertSame(<< + + + + + +EOF + , + $actualContents); + } + /** * @dataProvider getUnconfigureTests */ @@ -611,11 +685,16 @@ private function readFile(string $filename): string private function createComposerMockWithPackagesInstalled(array $packages) { + $packages = array_map(fn ($package) => explode(':', $package), $packages); + + $packageNames = array_column($packages, 0); + $constraints = array_column($packages, 1); + $repository = $this->getMockBuilder(InstalledRepositoryInterface::class)->getMock(); $repository->expects($this->any()) ->method('findPackage') - ->willReturnCallback(function ($name) use ($packages) { - if (\in_array($name, $packages)) { + ->willReturnCallback(function ($name, $constraint) use ($packageNames, $constraints) { + if (\in_array($name, $packageNames) && ('*' === $constraint || \in_array($constraint, $constraints))) { return new Package($name, '1.0.0', '1.0.0'); } From 68cdcde0b7e36b008a08bcf3709c07a20e757a29 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 4 Jul 2025 08:30:46 +0200 Subject: [PATCH 2/5] Fix CS --- src/Flex.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Flex.php b/src/Flex.php index fdaaf003a..9ef3060cb 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -121,9 +121,9 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__) // if Flex is being upgraded, the original operations from the original Flex // instance are stored in the static property, so we can reuse them now. - if (property_exists(Flex::class, 'storedOperations') && Flex::$storedOperations) { - $this->operations = Flex::$storedOperations; - Flex::$storedOperations = []; + if (property_exists(self::class, 'storedOperations') && self::$storedOperations) { + $this->operations = self::$storedOperations; + self::$storedOperations = []; } $symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? '')); @@ -213,7 +213,7 @@ public function deactivate(Composer $composer, IOInterface $io) { // Using `Flex::` instead of `self::` to avoid issues when // composer renames plugin classes when upgrading them - Flex::$storedOperations = $this->operations; + self::$storedOperations = $this->operations; self::$activated = false; } From 423c36e369361003dc31ef11c5f15fb589e52c01 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 5 Jul 2025 09:45:19 +0200 Subject: [PATCH 3/5] Revert "Fix CS" This reverts commit 68cdcde0b7e36b008a08bcf3709c07a20e757a29. --- src/Flex.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Flex.php b/src/Flex.php index 9ef3060cb..fdaaf003a 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -121,9 +121,9 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__) // if Flex is being upgraded, the original operations from the original Flex // instance are stored in the static property, so we can reuse them now. - if (property_exists(self::class, 'storedOperations') && self::$storedOperations) { - $this->operations = self::$storedOperations; - self::$storedOperations = []; + if (property_exists(Flex::class, 'storedOperations') && Flex::$storedOperations) { + $this->operations = Flex::$storedOperations; + Flex::$storedOperations = []; } $symfonyRequire = preg_replace('/\.x$/', '.x-dev', getenv('SYMFONY_REQUIRE') ?: ($composer->getPackage()->getExtra()['symfony']['require'] ?? '')); @@ -213,7 +213,7 @@ public function deactivate(Composer $composer, IOInterface $io) { // Using `Flex::` instead of `self::` to avoid issues when // composer renames plugin classes when upgrading them - self::$storedOperations = $this->operations; + Flex::$storedOperations = $this->operations; self::$activated = false; } From 2ca784372c92a1ba4ccb67537f15ea75cc13d83a Mon Sep 17 00:00:00 2001 From: Jawira Portugal Date: Tue, 8 Jul 2025 11:38:04 +0200 Subject: [PATCH 4/5] feat: Make DockerComposeConfigurator compatible with "false" string --- src/Configurator/DockerComposeConfigurator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configurator/DockerComposeConfigurator.php b/src/Configurator/DockerComposeConfigurator.php index 9a13906e2..5314aa7f2 100644 --- a/src/Configurator/DockerComposeConfigurator.php +++ b/src/Configurator/DockerComposeConfigurator.php @@ -101,7 +101,7 @@ public static function shouldConfigureDockerRecipe(Composer $composer, IOInterfa } if (null !== $dockerPreference = $composer->getPackage()->getExtra()['symfony']['docker'] ?? null) { - self::$configureDockerRecipes = $dockerPreference; + self::$configureDockerRecipes = filter_var($dockerPreference, \FILTER_VALIDATE_BOOLEAN); return self::$configureDockerRecipes; } From 3a96cbd44903554a213d89fb82ca425a8260303c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 29 Jul 2025 11:03:48 +0200 Subject: [PATCH 5/5] Leverage symfony-tools/fabbot --- .github/workflows/fabbot.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/fabbot.yml diff --git a/.github/workflows/fabbot.yml b/.github/workflows/fabbot.yml new file mode 100644 index 000000000..a6d4c5473 --- /dev/null +++ b/.github/workflows/fabbot.yml @@ -0,0 +1,14 @@ +name: CS + +on: + pull_request: + +permissions: + contents: read + +jobs: + call-fabbot: + name: Fabbot + uses: symfony-tools/fabbot/.github/workflows/fabbot.yml@main + with: + package: Symfony Flex