Skip to content

Commit

Permalink
Test each Symfony version
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Dec 7, 2023
1 parent 59fa602 commit 9bbe6b2
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 32 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/symfony.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Symfony

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 15
env:
COMPOSER_NO_INTERACTION: 1

strategy:
fail-fast: false
matrix:
php: [ 8.3 ]
symfony: [ 2, 3, 4, 5, 6, 7 ]

name: Symfony ${{ matrix.symfony }}

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, imagick
tools: composer:v2
coverage: none

- name: Cache library packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-

- name: Cache test packages
id: composer-test-cache
uses: actions/cache@v3
with:
path: src/test/vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-symfony-test-${{ matrix.symfony }}-${{ hashFiles('src/test/composer.lock') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-symfony-test-${{ matrix.symfony }}-

- name: Set Symfony version
run: |
composer require --no-update --no-interaction \
symfony/dependency-injection:^${{ matrix.symfony }} \
symfony/filesystem:^${{ matrix.symfony }} \
symfony/config:^${{ matrix.symfony }}
- name: Upgrade PHPUnit
if: matrix.php >= 7.2
run: cd src/test && composer require phpunit/phpunit:^5.7.27 --no-update --no-interaction --dev

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist --no-progress --prefer-stable --ignore-platform-req=php+

- name: Install test dependencies
if: steps.composer-test-cache.outputs.cache-hit != 'true'
run: cd src/test && composer update --prefer-dist --no-progress --prefer-stable --ignore-platform-req=php+

- name: Fix PHP compatibility
if: steps.composer-test-cache.outputs.cache-hit != 'true'
run: php src/test/php/fix-php-compatibility.php

- name: Check Symfony version
run: php src/test/symfony-version.php

- name: Run test suite
run: src/test/vendor/bin/phpunit -v
44 changes: 27 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Tests

on:
push:
branches:
- "*"
branches: [ '**' ]
pull_request:
branches:
- "*"
branches: [ '**' ]

jobs:
php-tests:
Expand All @@ -17,17 +15,17 @@ jobs:

strategy:
matrix:
php: [5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
dependency-version: [prefer-lowest, prefer-stable]
php: [ 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 ]
setup: [ lowest, stable ]
exclude:
- dependency-version: prefer-lowest
- setup: lowest
php: 7.2
- dependency-version: prefer-lowest
- setup: lowest
php: 7.3
- dependency-version: prefer-lowest
- setup: lowest
php: 7.4

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
name: PHP ${{ matrix.php }} - ${{ matrix.setup }}

steps:
- name: Checkout code
Expand All @@ -40,24 +38,36 @@ jobs:
coverage: none
tools: composer:v2

- name: Cache Composer packages
- name: Cache library packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependency-version }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependency-version }}
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.setup }}-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.setup }}-

- name: Cache test packages
id: composer-test-cache
uses: actions/cache@v3
with:
path: src/test/vendor
key: ${{ runner.os }}-php-test-${{ matrix.php }}-${{ matrix.setup }}-${{ hashFiles('src/test/composer.json') }}
restore-keys: ${{ runner.os }}-php-test-${{ matrix.php }}-${{ matrix.setup }}-

- name: Upgrade PHPUnit
if: matrix.php >= 7.2
run: composer require phpunit/phpunit:^5.7.27 --no-update --no-interaction --dev
run: cd src/test && composer require phpunit/phpunit:^5.7.27 --no-update --no-interaction --dev

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }}
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --no-progress --prefer-${{ matrix.setup }} --prefer-dist --no-progress --ignore-platform-req=php+

- name: Install test dependencies
if: steps.composer-test-cache.outputs.cache-hit != 'true'
run: cd src/test && composer update --no-progress --prefer-dist --prefer-stable --ignore-platform-req=php+

- name: Fix PHP compatibility
run: php src/test/php/fix-php-compatibility.php

- name: Execute Unit Tests
run: vendor/bin/phpunit
run: src/test/vendor/bin/phpunit -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/*.xml
composer.lock
vendor
src/test/vendor
dist
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.3.9",
"pdepend/pdepend": "^2.15.1",
"ext-xml": "*",
"composer/xdebug-handler": "^1.0 || ^2.0 || ^3.0"
"composer/xdebug-handler": "^1.0 || ^2.0 || ^3.0",
"pdepend/pdepend": "dev-fix/symfony-compatibility as 2.16.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.27",
"squizlabs/php_codesniffer": "^2.9.2 || ^3.7.2",
"mikey179/vfsstream": "^1.6.8",
"gregwar/rst": "^1.0",
Expand Down
9 changes: 9 additions & 0 deletions src/test/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "phpmd/phpmd-tester",
"license": "BSD-3-Clause",
"type": "library",
"require": {
"php": ">=5.3.9",
"phpunit/phpunit": "^4.8.36 || ^5.7.27"
}
}
37 changes: 25 additions & 12 deletions src/test/php/fix-php-compatibility.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

$vendorPath = __DIR__ . '/../vendor';
$replacements = array(
/**
* Patch phpunit/phpunit-mock-objects Generator.php file to not create double nullable tokens: `??`
*/
__DIR__ . '/../../../vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php' => array(
$vendorPath . '/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php' => array(
array(
"if (version_compare(PHP_VERSION, '7.1', '>=') && " .
"\$parameter->allowsNull() && !\$parameter->isVariadic()) {",
"if (version_compare(PHP_VERSION, '7.1', '>=') && version_compare(PHP_VERSION, '8.0', '<') && " .
"\$parameter->allowsNull() && !\$parameter->isVariadic()) {",
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Util/Configuration.php' => array(
$vendorPath . '/phpunit/phpunit/src/Util/Configuration.php' => array(
array(
'final private function',
'private function',
Expand All @@ -22,14 +23,20 @@
'',
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Framework/Constraint.php' => array(
$vendorPath . '/phpunit/phpunit/src/Framework/Constraint.php' => array(
array(
'public function count()',
"#[\\ReturnTypeWillChange]\npublic function count()",
'#[\\ReturnTypeWillChange]',
),
),
__DIR__ . '/../../../vendor/phpunit/php-token-stream/src/Token/Stream.php' => array(
$vendorPath . '/phpunit/php-token-stream/src/Token.php' => array(
array(
'$docComment = $this->getDocblock();',
'$docComment = (string) $this->getDocblock();',
),
),
$vendorPath . '/phpunit/php-token-stream/src/Token/Stream.php' => array(
array(
'public function offsetExists',
"#[\\ReturnTypeWillChange]\npublic function offsetExists",
Expand Down Expand Up @@ -86,7 +93,7 @@
'#[\\ReturnTypeWillChange]',
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Util/TestSuiteIterator.php' => array(
$vendorPath . '/phpunit/phpunit/src/Util/TestSuiteIterator.php' => array(
array(
'public function current',
"#[\\ReturnTypeWillChange]\npublic function current",
Expand Down Expand Up @@ -123,13 +130,13 @@
"#[\\ReturnTypeWillChange]\npublic function hasChildren",
),
),
__DIR__ . '/../../../vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php' => (PHP_VERSION >= 7) ? array(
$vendorPath . '/phpunit/php-code-coverage/src/Report/Html/Renderer/File.php' => (PHP_VERSION >= 7) ? array(
array(
'$numTests = count($coverageData[$i]);',
'$numTests = count($coverageData[$i] ?? []);',
),
) : array(),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Extensions/PhptTestCase.php' => array(
$vendorPath . '/phpunit/phpunit/src/Extensions/PhptTestCase.php' => array(
array(
'public function count()',
"#[\\ReturnTypeWillChange]\npublic function count()",
Expand All @@ -141,14 +148,14 @@
'xdebug.mode=coverage',
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Framework/TestCase.php' => array(
$vendorPath . '/phpunit/phpunit/src/Framework/TestCase.php' => array(
array(
'public function count(',
"#[\\ReturnTypeWillChange]\npublic function count(",
'#[\\ReturnTypeWillChange]',
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Framework/TestSuite.php' => array(
$vendorPath . '/phpunit/phpunit/src/Framework/TestSuite.php' => array(
array(
'public function count(',
"#[\\ReturnTypeWillChange]\npublic function count(",
Expand All @@ -160,7 +167,7 @@
'#[\\ReturnTypeWillChange]',
),
),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Framework/TestResult.php' => array(
$vendorPath . '/phpunit/phpunit/src/Framework/TestResult.php' => array(
array(
'public function count(',
"#[\\ReturnTypeWillChange]\npublic function count(",
Expand All @@ -172,14 +179,20 @@
'#[\\ReturnTypeWillChange]',
),
),
__DIR__ . '/../../../vendor/phpunit/php-code-coverage/src/CodeCoverage.php' => (PHP_VERSION >= 7) ? array(
$vendorPath . '/phpunit/phpunit/src/Util/Getopt.php' => array(
array(
'strlen($opt_arg)',
'strlen((string) $opt_arg)',
),
),
$vendorPath . '/phpunit/php-code-coverage/src/CodeCoverage.php' => (PHP_VERSION >= 7) ? array(
array(
'$docblock = $token->getDocblock();',
'$docblock = $token->getDocblock() ?? \'\';',
'$docblock = $token->getDocblock() ?? \'\';',
),
) : array(),
__DIR__ . '/../../../vendor/phpunit/phpunit/src/Runner/Filter/Test.php' => array(
$vendorPath . '/phpunit/phpunit/src/Runner/Filter/Test.php' => array(
array(
'public function accept(',
"#[\\ReturnTypeWillChange]\npublic function accept(",
Expand Down
19 changes: 19 additions & 0 deletions src/test/symfony-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$installed = require __DIR__.'/../../vendor/composer/installed.php';
$versions = $installed['versions'];

$symfonyPackages = array(
'config',
'dependency-injection',
'filesystem',
'yaml'
);

foreach ($symfonyPackages as $package) {
echo "$package: ".
(isset($versions['symfony/'.$package]['pretty_version'])
? $versions['symfony/'.$package]['pretty_version']
: 'not installed').
"\n";
}

0 comments on commit 9bbe6b2

Please sign in to comment.