Skip to content

Commit eed55ee

Browse files
DjordyKoertCopilot
andauthored
ci: test optional dependencies separately (#2645)
## Description Run optional-dependencies. This should help with determining if a major version bump of Symfony (8) is safe to do without needing to wait for external bundles to update their version constraints (or build support) Related to #2612 ## What type of PR is this? (check all applicable) - [ ] Bug Fix - [ ] Feature - [ ] Refactor - [ ] Deprecation - [ ] Breaking Change - [ ] Documentation Update - [x] CI ## Checklist - [ ] I have made corresponding changes to the documentation (`docs/`) --------- Co-authored-by: Copilot <[email protected]>
1 parent 208b4cf commit eed55ee

File tree

11 files changed

+113
-43
lines changed

11 files changed

+113
-43
lines changed

.github/workflows/common/composer-install/action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ inputs:
1111
description: Additional flags that are passed to the `composer update` step
1212
required: false
1313
type: string
14+
15+
test-group:
16+
description: The test group to run, used to remove other optional dependencies.
17+
required: false
18+
type: string
1419

1520
runs:
1621
using: composite
@@ -33,6 +38,21 @@ runs:
3338
run: "composer config minimum-stability stable"
3439
shell: bash
3540

41+
- name: "Remove friendsofsymfony/rest-bundle"
42+
run: "composer remove friendsofsymfony/rest-bundle --dev --no-update"
43+
shell: bash
44+
if: "${{ inputs.test-group != 'fos-rest' && inputs.test-group != 'all' }}"
45+
46+
- name: "Remove willdurand/hateoas-bundle"
47+
run: "composer remove willdurand/hateoas-bundle willdurand/negotiation --dev --no-update"
48+
shell: bash
49+
if: "${{ inputs.test-group != 'hateoas' && inputs.test-group != 'all' }}"
50+
51+
- name: "Remove jms/serializer-bundle"
52+
run: "composer remove jms/serializer-bundle jms/serializer --dev --no-update"
53+
shell: bash
54+
if: "${{ inputs.test-group != 'jms-serializer' && inputs.test-group != 'all' }}"
55+
3656
- name: Install dependencies with Composer
3757
env:
3858
SYMFONY_REQUIRE: "${{ inputs.symfony-version }}.*"

.github/workflows/continuous-integration.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27+
test-group:
28+
- core
29+
- fos-rest
30+
- jms-serializer
31+
- hateoas
2732
php-version:
2833
- 8.2
2934
- 8.3
@@ -37,9 +42,38 @@ jobs:
3742
composer-flags:
3843
- ""
3944
include:
40-
- php-version: 8.2
45+
- test-group: core
46+
php-version: 8.2
4147
symfony-require: "6.4"
4248
composer-flags: "--prefer-lowest"
49+
exclude:
50+
# Test only the lowest and highest PHP versions for each optional dependency test group
51+
- test-group: fos-rest
52+
php-version: 8.3
53+
- test-group: fos-rest
54+
php-version: 8.4
55+
- test-group: jms-serializer
56+
php-version: 8.3
57+
- test-group: jms-serializer
58+
php-version: 8.4
59+
- test-group: hateoas
60+
php-version: 8.3
61+
- test-group: hateoas
62+
php-version: 8.4
63+
# Test only the highest versions for a symfony major for each optional dependency test group
64+
- test-group: fos-rest
65+
symfony-require: "7.2"
66+
- test-group: fos-rest
67+
symfony-require: "7.3"
68+
- test-group: jms-serializer
69+
symfony-require: "7.2"
70+
- test-group: jms-serializer
71+
symfony-require: "7.3"
72+
- test-group: hateoas
73+
symfony-require: "7.2"
74+
- test-group: hateoas
75+
symfony-require: "7.3"
76+
4377
steps:
4478
- name: Checkout
4579
uses: actions/checkout@v6
@@ -58,18 +92,25 @@ jobs:
5892
with:
5993
symfony-version: ${{ matrix.symfony-require }}
6094
composer-flags: ${{ matrix.composer-flags }}
95+
test-group: ${{ matrix.test-group }}
6196

6297
- name: PHPUnit Tests
63-
run: |
98+
run: |
99+
if [ "${{ matrix.test-group }}" == "core" ]; then
100+
PHPUNIT_ARGS="--exclude-group fos-rest,jms-serializer,hateoas"
101+
else
102+
PHPUNIT_ARGS="--group ${{ matrix.test-group }}"
103+
fi
104+
64105
vendor/bin/phpunit \
65106
--configuration phpunit.xml.dist \
66-
--log-junit=junit-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.doctrine-annotations }}${{ matrix.composer-flags }}.xml \
67-
--coverage-clover=coverage-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.doctrine-annotations }}${{ matrix.composer-flags }}.xml \
68-
--coverage-filter=src/
69-
107+
--log-junit=junit-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.test-group }}.xml \
108+
--coverage-clover=coverage-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.test-group }}.xml \
109+
--coverage-filter=src/ \
110+
$PHPUNIT_ARGS
70111
- uses: actions/upload-artifact@v5
71112
with:
72-
name: phpunit-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.doctrine-annotations }}${{ matrix.composer-flags }}
113+
name: phpunit-${{ matrix.php-version }}-${{ matrix.symfony-require }}-${{ matrix.test-group }}${{ matrix.composer-flags }}
73114
path: |
74115
coverage*.xml
75116
junit*.xml
@@ -127,6 +168,7 @@ jobs:
127168
uses: ./.github/workflows/common/composer-install
128169
with:
129170
symfony-version: "7.2.*"
171+
test-group: all
130172

131173
- name: Run PHP-CS-Fixer
132174
run: vendor/bin/php-cs-fixer check -v --diff
@@ -152,6 +194,7 @@ jobs:
152194
uses: ./.github/workflows/common/composer-install
153195
with:
154196
symfony-version: "7.2.*"
197+
test-group: all
155198

156199
- name: Run PHPStan
157200
run: vendor/bin/phpstan analyse --no-progress --no-interaction

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"symfony/deprecation-contracts": "^2.1 || ^3",
2929
"symfony/framework-bundle": "^6.4 || ^7.2",
3030
"symfony/http-foundation": "^6.4 || ^7.2",
31-
"symfony/type-info": "^7.2",
3231
"symfony/http-kernel": "^6.4 || ^7.2",
3332
"symfony/options-resolver": "^6.4 || ^7.2",
3433
"symfony/property-info": "^6.4 || ^7.2",
3534
"symfony/routing": "^6.4 || ^7.2",
35+
"symfony/type-info": "^7.2",
3636
"zircote/swagger-php": "^4.11.1 || ^5.0"
3737
},
3838
"require-dev": {
@@ -50,6 +50,7 @@
5050
"symfony/browser-kit": "^6.4 || ^7.2",
5151
"symfony/cache": "^6.4 || ^7.2",
5252
"symfony/dom-crawler": "^6.4 || ^7.2",
53+
"symfony/expression-language": "^6.4 || ^7.2",
5354
"symfony/finder": "^6.4 || ^7.2",
5455
"symfony/form": "^6.4 || ^7.2",
5556
"symfony/phpunit-bridge": "^6.4 || ^7.2",

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
stopOnFailure="false"
1111
bootstrap="vendor/autoload.php"
1212
displayDetailsOnTestsThatTriggerWarnings="true"
13+
failOnEmptyTestSuite="true"
1314
>
1415
<php>
1516
<env name="SHELL_VERBOSITY" value="-1" />

tests/Functional/BazingaFunctionalTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
use Metadata\Cache\PsrCacheAdapter;
1515
use Metadata\MetadataFactory;
16+
use PHPUnit\Framework\Attributes\Group;
1617
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1718
use Symfony\Component\HttpKernel\KernelInterface;
1819

20+
#[Group('hateoas')]
1921
class BazingaFunctionalTest extends WebTestCase
2022
{
2123
protected function setUp(): void

tests/Functional/ControllerTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OpenApi\Annotations as OA;
1818
use OpenApi\Processors\CleanUnusedComponents;
1919
use PHPUnit\Framework\Attributes\DataProvider;
20+
use PHPUnit\Framework\Attributes\Group;
2021
use Symfony\Component\DependencyInjection\Definition;
2122
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
2223
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -80,6 +81,24 @@ public function testControllers(?string $controller, ?string $fixtureSuffix = nu
8081
);
8182
}
8283

84+
#[Group('jms-serializer')]
85+
#[Group('hateoas')]
86+
public function testJmsModelOptOut(): void
87+
{
88+
$this->testControllers(
89+
'JmsOptOutController',
90+
null,
91+
[new JMSSerializerBundle()],
92+
[
93+
'nelmio_api_doc' => [
94+
'models' => [
95+
'use_jms' => true,
96+
],
97+
],
98+
],
99+
);
100+
}
101+
83102
public static function provideTestCases(): \Generator
84103
{
85104
yield 'Promoted properties defaults attributes' => [
@@ -94,19 +113,6 @@ public static function provideTestCases(): \Generator
94113
],
95114
];
96115

97-
yield 'JMS model opt out' => [
98-
'JmsOptOutController',
99-
null,
100-
[new JMSSerializerBundle()],
101-
[
102-
'nelmio_api_doc' => [
103-
'models' => [
104-
'use_jms' => true,
105-
],
106-
],
107-
],
108-
];
109-
110116
yield 'https://github.com/nelmio/NelmioApiDocBundle/issues/2209' => [
111117
'Controller2209',
112118
];

tests/Functional/FOSRestTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use OpenApi\Annotations as OA;
1515
use OpenApi\Generator;
1616
use PHPUnit\Framework\Attributes\DataProvider;
17+
use PHPUnit\Framework\Attributes\Group;
1718
use Symfony\Component\HttpKernel\KernelInterface;
1819

20+
#[Group('fos-rest')]
1921
class FOSRestTest extends WebTestCase
2022
{
2123
/**

tests/Functional/JMSFunctionalTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
namespace Nelmio\ApiDocBundle\Tests\Functional;
1313

14+
use PHPUnit\Framework\Attributes\Group;
1415
use Symfony\Component\HttpKernel\KernelInterface;
1516

17+
#[Group('jms-serializer')]
18+
#[Group('hateoas')]
1619
class JMSFunctionalTest extends WebTestCase
1720
{
1821
protected function setUp(): void

tests/Functional/TestKernel.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ public function registerBundles(): iterable
6262
new ApiPlatformBundle(),
6363
new NelmioApiDocBundle(),
6464
new TestBundle(),
65-
new FOSRestBundle(),
6665
];
6766

67+
if (self::USE_FOSREST === $this->flag) {
68+
$bundles[] = new FOSRestBundle();
69+
}
70+
6871
if (self::USE_JMS === $this->flag || self::USE_BAZINGA === $this->flag) {
6972
$bundles[] = new JMSSerializerBundle();
7073

@@ -137,20 +140,16 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
137140
]],
138141
]);
139142

140-
$c->loadFromExtension('fos_rest', [
141-
'format_listener' => [
142-
'rules' => [
143-
[
144-
'path' => '^/',
145-
'fallback_format' => 'json',
143+
if (self::USE_FOSREST === $this->flag) {
144+
$c->loadFromExtension('fos_rest', [
145+
'format_listener' => [
146+
'rules' => [
147+
[
148+
'path' => '^/',
149+
'fallback_format' => 'json',
150+
],
146151
],
147152
],
148-
],
149-
]);
150-
151-
// If FOSRestBundle 2.8
152-
if (class_exists(\FOS\RestBundle\EventListener\ResponseStatusCodeListener::class)) {
153-
$c->loadFromExtension('fos_rest', [
154153
'exception' => [
155154
'enabled' => false,
156155
'exception_listener' => false,

tests/RouteDescriber/FosRestDescriberTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
use Nelmio\ApiDocBundle\RouteDescriber\FosRestDescriber;
1616
use OpenApi\Annotations\OpenApi;
1717
use OpenApi\Generator;
18+
use PHPUnit\Framework\Attributes\Group;
1819
use PHPUnit\Framework\TestCase;
1920
use Symfony\Component\Routing\Route;
2021
use Symfony\Component\Validator\Constraints\Choice;
2122

23+
#[Group('fos-rest')]
2224
class FosRestDescriberTest extends TestCase
2325
{
2426
public function testQueryParamWithChoiceConstraintIsAddedAsEnum(): void

0 commit comments

Comments
 (0)