Skip to content

Checks the Symfony different version compatibilies in the CI #122

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

Merged
merged 7 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
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
37 changes: 36 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,42 @@ jobs:
uses: "ramsey/composer-install@v2"

- name: "Run tests"
run: "make test"
run: "make phpunit"

symfony-version:
runs-on: "ubuntu-latest"
name: "Test ${{ matrix.php }} with Symfony ${{ matrix.symfony.version }}"
strategy:
fail-fast: false
matrix:
php:
- "7.4"
- "8.0"
- "8.1"
symfony:
- version: "4.4"
conflict: ">=5.0"
- version: "5.4"
conflict: ">=6.0,<5.0"

steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"

- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
tools: "composer"

- name: "Fix the Symfony versions"
run: "bin/fix-symfony-versions \"${{ matrix.symfony.conflict }}\""

- name: "Install Composer dependencies"
uses: "ramsey/composer-install@v2"

- name: "Run tests"
run: "make phpunit"

infection:
runs-on: "ubuntu-latest"
Expand Down
4 changes: 4 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
->setFinder(
Finder::create()
->in(__DIR__)
->append([
'.github/fix-symfony-versions',
'set-composer-conflicts.php',
])
->exclude([
'dist',
'tests/Integration/var',
Expand Down
56 changes: 56 additions & 0 deletions bin/fix-symfony-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Webmozarts Console Parallelization package.
*
* (c) Webmozarts GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Webmozarts\Console\Parallelization\CI;

use function file_get_contents;
use function file_put_contents;
use function json_decode;
use function json_encode;
use function shell_exec;
use const JSON_PRETTY_PRINT;
use const JSON_UNESCAPED_SLASHES;

require_once __DIR__.'/set-composer-conflicts.php';

$composerJsonPath = __DIR__.'/../composer.json';

$packagesToFix = [
'symfony/cache',
'symfony/config',
'symfony/console',
'symfony/dependency-injection',
'symfony/error-handler',
'symfony/event-dispatcher',
'symfony/filesystem',
'symfony/finder',
'symfony/framework-bundle',
'symfony/http-foundation',
'symfony/http-kernel',
'symfony/process',
'symfony/routing',
'symfony/string',
'symfony/var-dumper',
'symfony/var-exporter',
];

$decodedComposerJson = json_decode(file_get_contents($composerJsonPath));

set_composer_conflicts(
$decodedComposerJson,
$packagesToFix,
$argv[1] ?? null,
);

file_put_contents($composerJsonPath, json_encode($decodedComposerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
43 changes: 43 additions & 0 deletions bin/set-composer-conflicts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Webmozarts Console Parallelization package.
*
* (c) Webmozarts GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Webmozarts\Console\Parallelization\CI;

use function count;
use stdClass;

/**
* @param list<non-empty-string> $packageNames
* @param non-empty-string|null $conflict
*/
function set_composer_conflicts(
stdClass $decodedComposerJson,
array $packageNames,
?string $conflict
): void {
if (0 === count($packageNames)) {
return;
}

$decodedComposerJson->conflict = $decodedComposerJson->conflict ?? new stdClass();

if (null === $conflict) {
foreach ($packageNames as $packageName) {
unset($decodedComposerJson->conflict->$packageName);
}
} else {
foreach ($packageNames as $packageName) {
$decodedComposerJson->conflict->$packageName = $conflict;
}
}
}
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
level: 5
paths:
- bin/set-composer-conflicts.php
- src
- tests
excludePaths:
Expand Down
122 changes: 122 additions & 0 deletions tests/SetComposerConflictsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

/*
* This file is part of the Webmozarts Console Parallelization package.
*
* (c) Webmozarts GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Webmozarts\Console\Parallelization;

require_once __DIR__.'/../bin/set-composer-conflicts.php';

use function is_array;
use PHPUnit\Framework\TestCase;
use stdClass;
use function Webmozarts\Console\Parallelization\CI\set_composer_conflicts;

/**
* @coversNothing
*/
final class SetComposerConflictsTest extends TestCase
{
/**
* @dataProvider conflictProvider
*
* @param list<non-empty-string> $packageNames
* @param non-empty-string|null $conflict
*/
public function test_it_can_the_desired_packages_to_the_composer_conflict_section(
stdClass $decodedComposerJson,
array $packageNames,
?string $conflict,
stdClass $expected
): void {
set_composer_conflicts($decodedComposerJson, $packageNames, $conflict);

self::assertEquals($expected, $decodedComposerJson);
}

public static function conflictProvider(): iterable
{
yield 'nominal' => [
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
]),
['symfony/cache', 'symfony/framework-bundle'],
'>=5.0',
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
'conflict' => [
'symfony/cache' => '>=5.0',
'symfony/framework-bundle' => '>=5.0',
],
]),
];

yield 'no packages' => [
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
]),
[],
'>=5.0',
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
]),
];

yield 'already has a conflict section' => [
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
'conflict' => [
'symfony/service-contracts' => '<2.0',
],
]),
['symfony/cache', 'symfony/framework-bundle'],
'>=5.0',
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
'conflict' => [
'symfony/service-contracts' => '<2.0',
'symfony/cache' => '>=5.0',
'symfony/framework-bundle' => '>=5.0',
],
]),
];

yield 'removes conflicts if no conflict is provided' => [
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
'conflict' => [
'symfony/service-contracts' => '<2.0',
'symfony/cache' => '>=5.0',
'symfony/framework-bundle' => '>=5.0',
],
]),
['symfony/cache', 'symfony/framework-bundle'],
null,
self::toStdClass([
'package' => 'webmozarts/console-parallelization',
'conflict' => [
'symfony/service-contracts' => '<2.0',
],
]),
];
}

private static function toStdClass(array $value): stdClass
{
foreach ($value as $key => $item) {
if (is_array($item)) {
$value[$key] = self::toStdClass($item);
}
}

return (object) $value;
}
}