Skip to content

Commit

Permalink
Merge pull request #23 from denga/symfony-v6-support
Browse files Browse the repository at this point in the history
Add Symfony 6.x support
  • Loading branch information
cs278 authored Feb 3, 2023
2 parents 6c8f02a + de8c900 commit 7f4e4ea
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 47 additions & 2 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -180,14 +191,48 @@ public function dataRun(): iterable
}
}

private static function executeCondition(string $condition): bool
/** @return array<string,string> */
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));
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/verbose_debug_no_errors.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
No packages results in no errors (debug level messages)
--CONDITION--
true
$isPackage('symfony/deprecation-contracts', '*')
--COMPOSER--
{}
--ARGS--
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/verbose_debug_no_errors_2.test
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 7f4e4ea

Please sign in to comment.