From 27c38e040ed5f0f3f92ccbfc7f20314aeb93d531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=A4deke?= Date: Mon, 8 Aug 2022 14:33:25 +0200 Subject: [PATCH 1/3] Add symfony 6.x support --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0e433fc..512bf80 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ "require": { "php": ">= 7.1", "composer-plugin-api": "^1.1 || ^2", - "symfony/yaml": "^4.4 || ^5" + "symfony/yaml": "^4.4 || ^5 || ^6" }, "require-dev": { "cs278/mktemp": "^1", "composer/composer": "^1 || ^2@RC", "composer/semver": "*", - "symfony/filesystem": "^4.4 || ^5", + "symfony/filesystem": "^4.4 || ^5 || ^6", "symfony/phpunit-bridge": "^5.2", - "symfony/process": "^4.4 || ^5" + "symfony/process": "^4.4 || ^5 || ^6" }, "conflict": { "symfony/yaml": "=4.4.27 || =4.4.28 || =5.2.12 || =5.2.13 || =5.3.4 || =5.3.5" From f659f6499ed9ab363725910bd4b7632c748e13e3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 3 Feb 2023 17:13:10 +0000 Subject: [PATCH 2/3] Allow tests to skip depending on installed packages --- tests/integration/IntegrationTest.php | 49 +++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 9a57c76..3825055 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -126,9 +126,20 @@ public function testRun(int $expectedExit, string $expectedOutput, string $condi // Update the lock file with new requirements. file_put_contents($workingDir.'/composer.json', json_encode($composerJson)); $composer('update', '--no-install')->mustRun(); + + $lockedPackages = self::extractLockedPackages($workingDir.'/composer.lock'); } else { file_put_contents($workingDir.'/composer.json', json_encode($composerJson)); $composer('update')->mustRun(); + + $lockedPackages = file_exists($workingDir.'/composer.lock') + ? self::extractLockedPackages($workingDir.'/composer.lock') + : null; + } + + // Execute condition again now package data is available. + if (!self::executeCondition($condition, $lockedPackages)) { + $this->markTestSkipped($condition); } $proc = $composer('security-audit', ...$args); @@ -180,14 +191,48 @@ public function dataRun(): iterable } } - private static function executeCondition(string $condition): bool + /** @return array */ + private static function extractLockedPackages(string $lockFile): array + { + $result = \json_decode(file_get_contents($lockFile), true); + + if ($result === null) { + throw new \RuntimeException(sprintf('Failed to parse lock file: %s', $lockFile)); + } + + $packages = []; + + foreach (['packages', 'packages-dev'] as $type) { + if (isset($result[$type])) { + foreach ($result[$type] as $package) { + $packages[$package['name']] = $package['version']; + } + } + } + + return $packages; + } + + private static function executeCondition(string $condition, array $packages = null): bool { $template = <<<'EOT' $isComposer = function ($constraint) { return \Composer\Semver\Semver::satisfies(\Composer\Composer::VERSION, $constraint); }; -return %s; +if ($packages === null) { + $isPackage = function () { return true; }; +} else { + $isPackage = function (string $package, string $constraint) use ($packages) { + return isset($packages[$package]) + ? \Composer\Semver\Semver::satisfies($packages[$package], $constraint) + : false; + }; +} + +unset($packages); // Prevent direct access to packages data. + +return (%1$s); EOT; return (bool) eval(sprintf($template, $condition)); From de8c9007d4fb883099320442fe26b066bf397bfc Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 3 Feb 2023 17:13:34 +0000 Subject: [PATCH 3/3] Fix tests on Symfony 6 --- tests/integration/verbose_debug_no_errors.test | 2 +- tests/integration/verbose_debug_no_errors_2.test | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/integration/verbose_debug_no_errors_2.test diff --git a/tests/integration/verbose_debug_no_errors.test b/tests/integration/verbose_debug_no_errors.test index 7d257a9..48dbcfc 100644 --- a/tests/integration/verbose_debug_no_errors.test +++ b/tests/integration/verbose_debug_no_errors.test @@ -1,7 +1,7 @@ --TEST-- No packages results in no errors (debug level messages) --CONDITION-- -true +$isPackage('symfony/deprecation-contracts', '*') --COMPOSER-- {} --ARGS-- diff --git a/tests/integration/verbose_debug_no_errors_2.test b/tests/integration/verbose_debug_no_errors_2.test new file mode 100644 index 0000000..8a76abb --- /dev/null +++ b/tests/integration/verbose_debug_no_errors_2.test @@ -0,0 +1,15 @@ +--TEST-- +No packages results in no errors (debug level messages) +--CONDITION-- +!$isPackage('symfony/deprecation-contracts', '*') +--COMPOSER-- +{} +--ARGS-- +-vvv +--EXPECT-EXIT-- +0 +--EXPECT-OUTPUT-- +Checking cs278/composer-audit (N/A) for advisories... +Checking symfony/polyfill-ctype (N/A) for advisories... +Checking symfony/yaml (N/A) for advisories... +No advisories found for any packages.