Skip to content

fix(symfony): Symfony 8.1 compatibility#7955

Merged
soyuka merged 7 commits intoapi-platform:4.3from
soyuka:fix/json-streamer-symfony-8.1-7954
May 7, 2026
Merged

fix(symfony): Symfony 8.1 compatibility#7955
soyuka merged 7 commits intoapi-platform:4.3from
soyuka:fix/json-streamer-symfony-8.1-7954

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 7, 2026

Q A
Branch? 4.3
Tickets Closes #7954
License MIT
Doc PR

Symfony 8.1.0-BETA1 introduces a few removals and behaviour changes that
make API Platform 4.3 fail to compile its container or boot the test app.
This PR brings 4.3 up to compatibility and adds a dedicated CI lane so
the combination is exercised on every PR going forward.

What it changes

  • JsonStreamer — Skip API Platform's own DateTimeValueObjectTransformer
    registration when FrameworkBundle 8.1+ is detected. FrameworkBundle 8.1
    registers the transformer itself and ships a deprecation pass that
    upgrades the now-deprecated json_streamer.value_transformer tag, which
    fails TransformerPass validation against our service.

  • ConfigBuilder — Fluent Symfony\Config\* typed-closure config files
    were deprecated in symfony/dependency-injection 7.4 and the fallback
    was removed in 8.1. Migrate tests/Fixtures/app/config/config_swagger.php
    to ContainerConfigurator::extension() (BC across all supported
    FrameworkBundle versions).

  • ObjectMapper — Mirror FrameworkBundle's own willBeAvailable gate
    before loading our object-mapper wiring (state/object_mapper.php,
    mcp/mcp.php). When symfony/object-mapper is dev-only,
    FrameworkBundle skips its object_mapper service registration; without
    this gate, our alias dangles and breaks compilation.

  • Test app — Move config_behat_*.yml imports out of the
    database-specific configs and load them conditionally from AppKernel
    only when behat/behat and the local Behat context classes are
    available. Without this, the kernel cannot boot in any environment that
    does not have behat installed — including a Symfony 8.1 install,
    because friends-of-behat/* and soyuka/contexts cap behat at 3.x and
    behat 3.x caps symfony/console at <8.

  • CI — Add a phpunit-symfony-edge lane that drops behat dev deps,
    pins symfony/framework-bundle and symfony/json-streamer to
    8.1.x-dev, and runs PHPUnit. continue-on-error: true since 8.1 is
    pre-stable; the lane is informational until Symfony 8.1 ships stable.

…meworkBundle 8.1+

FrameworkBundle 8.1 registers DateTimeValueObjectTransformer itself as
.json_streamer.value_object_transformer.date_time and ships
DeprecateJsonStreamerValueTransformerTagPass, which appends the
json_streamer.property_value_transformer tag to every service still
carrying the deprecated json_streamer.value_transformer tag. Our service
implements ValueObjectTransformerInterface, not
PropertyValueTransformerInterface, so TransformerPass validation rejects
the container.

Gate the registration on the absence of the deprecation pass so we only
register on json-streamer 8.1 + framework-bundle <8.1, and drop the
deprecated tag from our own registration.

Closes api-platform#7954
@soyuka soyuka force-pushed the fix/json-streamer-symfony-8.1-7954 branch from 56c1cae to fd4d6f2 Compare May 7, 2026 08:00
@soyuka soyuka changed the title fix(symfony): skip DateTimeValueObjectTransformer registration on FrameworkBundle 8.1+ feat(symfony): Symfony 8.1 compatibility May 7, 2026
@soyuka soyuka force-pushed the fix/json-streamer-symfony-8.1-7954 branch from c527b60 to b815924 Compare May 7, 2026 10:52
soyuka added 4 commits May 7, 2026 13:13
…-streamer)

The existing phpunit-symfony-next lane resolves to framework-bundle
8.0.x-dev because behat/* and friends-of-behat/* dev deps cap
symfony/console at <8, which excludes framework-bundle 8.1. This means
the FB 8.1 + json-streamer 8.1 combination — the one that triggers
issue api-platform#7954 — is not exercised in CI today.

Add a dedicated phpunit-symfony-edge lane that drops the behat dev deps
before resolving and explicitly pins framework-bundle and json-streamer
to 8.1.x-dev. Marked continue-on-error since 8.1 is still pre-stable
and unrelated upstream breakage shouldn't block PRs.
…ists

The Symfony 8.1 PHPUnit lane removes friends-of-behat/symfony-extension
from the dev deps to satisfy framework-bundle 8.1 / symfony-console 8
constraints. cache:clear runs outside the phpunit env, so $_ENV[APP_PHPUNIT]
is null and the kernel tries to instantiate a class that no longer exists.

Mirror the existing class_exists gates on DoctrineMongoDBBundle and McpBundle
so the kernel boots cleanly in any environment that doesn't have the bundle
installed.
Move config_behat_*.yml imports out of the database-specific config files
and load them conditionally from AppKernel only when behat/behat is
installed and tests/Behat context classes are available. The DoctrineContext
service tweak is gated on the same condition.

This unblocks running PHPUnit against the test app on dependency sets that
exclude behat — needed to test against Symfony 8.1, where the friends-of-behat
ecosystem has not yet shipped a symfony/console 8 compatible release.
* Migrate config_swagger.php from the fluent ConfigBuilder pattern (deprecated
  in symfony/dependency-injection 7.4, removed in 8.1: PhpFileLoader no longer
  generates Symfony\Config\* classes) to ContainerConfigurator::extension().
* Gate state/object_mapper.php and mcp/mcp.php loading on
  ContainerBuilder::willBeAvailable for symfony/object-mapper, mirroring
  FrameworkBundle's own gate. Without this, an alias to a non-existent
  "object_mapper" service breaks container compilation when object-mapper
  is dev-only.
@soyuka soyuka force-pushed the fix/json-streamer-symfony-8.1-7954 branch from b815924 to 141adc8 Compare May 7, 2026 11:13
Symfony 8.1 added a "set" property hook on Request::$query that triggers
a deprecation when the property is assigned directly. PHPUnit's stub
generator cannot wrap the hook because its return type "InputBag" is
final, so createStub(Request::class) fails with:

    Class "Symfony\Component\HttpFoundation\InputBag" is declared "final"
    and cannot be doubled

Use a real anonymous Request subclass that overrides getBaseUrl() instead.
Comment thread tests/Symfony/Bundle/SwaggerUi/SwaggerUiProviderTest.php Outdated
Comment thread .github/workflows/ci.yml
- name: Run Behat tests
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction

phpunit-symfony-edge:
Copy link
Copy Markdown
Member Author

@soyuka soyuka May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get removed once behat (and its dependencies) aligns for the symfony's dependencies

Comment thread .github/workflows/ci.yml
Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
@soyuka soyuka changed the title feat(symfony): Symfony 8.1 compatibility fix(symfony): Symfony 8.1 compatibility May 7, 2026
@soyuka soyuka merged commit 78c4ddf into api-platform:4.3 May 7, 2026
115 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant