Skip to content

Conversation

@Kocal
Copy link
Contributor

@Kocal Kocal commented Nov 4, 2025

Related to FriendsOfBehat/SymfonyExtension#218

This PR increase version constraints on symfony/* packages to allow Symfony 8, which will be released this month.

The CI fails because no version of PHP-CS-Fixer is compatible with Symfony 8, I'm on it.
EDIT: switched to php-cs-fixer/shim package

@keradus
Copy link

keradus commented Nov 4, 2025

you can also switch to php-cs-fixer/shim and not be blocked by dependencies of Fixer

@Kocal
Copy link
Contributor Author

Kocal commented Nov 4, 2025

Oh yeah you're right, I forgot about this package. Thanks! :)

@Kocal Kocal force-pushed the symfony-8 branch 3 times, most recently from a8a3a0c to 9f4f929 Compare November 4, 2025 23:13
@VincentLanglet
Copy link

Seems like you forgot one place return type hint @Kocal

Behat\Behat\Tester\ServiceContainer\TesterExtension::process

@Kocal Kocal force-pushed the symfony-8 branch 2 times, most recently from dec2ab7 to f2c6a86 Compare November 6, 2025 18:44
@Kocal
Copy link
Contributor Author

Kocal commented Nov 6, 2025

Oops, thanks, it should be fine now! :)

There is still a small issue here, someone from Symfony must create the tag 3.6.1 on symfony/translation-contracts, and we will be good:

  Problem 1
    - Root composer.json requires symfony/translation ^5.4 || ^6.4 || ^7.0 || ^8.0 -> satisfiable by symfony/translation[v8.0.0-BETA1].
    - symfony/translation v8.0.0-BETA1 requires symfony/translation-contracts ^3.6.1 -> found symfony/translation-contracts[dev-main, 3.6.x-dev (alias of dev-main)] but it does not match your minimum-stability.

@VincentLanglet
Copy link

Constraint will be relaxed symfony/symfony#62336

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

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

@Kocal thanks for doing this.

There are a few classes where adding the void return typehint required by the Symfony 8 CompilerPassInterface interface will technically break BC in Behat.

In some of these cases I'm not actually sure why our class isn't final as most of them are and they don't look like things we'd want users to extend. So the risk of breaking BC on those is fairly small.

However the one that's not so visible in the diff (except in the feature examples) is obviously our Extension interface itself, because that extends the symfony one.

So any/every third-party Behat extension a project is using will also need to be updated to add the return typehints before it can be used with symfony 8 (and may not itself have a dependency on the symfony version, since they are apparently only implementing "our" interface).

I'm therefore leaning to thinking this has to be a new major Behat version. We could make that a very small release, with just this and a few other "shouldn't affect anyone but could do" internal things that we've been holding off on, to make it easy for end-users to update.

There are bigger plans for "a future Behat major" but IMO we should probably keep them separate from one that's required for dependency version support.

This would mean that people will need to wait for third-party extensions to update their composer requirements to allow the new Behat major - but since they'd also need to have the return typehints to work in a project with symfony 8 that probably isn't a big deal...

I'm still deciding what I think about this, opinions/arguments very welcome.

SYMFONY_REQUIRE: ${{ matrix.symfony-version }}.*
run: composer update ${{ matrix.php == '8.5' && '--ignore-platform-req=php+' || '' }}
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: composer update ${{ (matrix.php == '8.4' || matrix.php == '8.5') && '--ignore-platform-req=php+' || '' }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually still need to ignore platform requirements on PHP 8.4? It's passing without this in master currently and I don't think symfony 8 will add any non-php-84 dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not clear on the rationale for this change. I've just tried installing locally on 8.4 with the SYMFONY_REQUIRE set to 8.0.* and I'm getting the same packages with & without the --ignore-platform-req flag.

AFAICS we only need that on 8.5 to allow us to install with dependencies that don't officially support 8.5 yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really remember why TBH, I will remove it

@stof
Copy link
Member

stof commented Nov 7, 2025

@acoulton I'm in favor of doing a new major version focused on native typing on extension-impacting APIs (and potentially making some of our classes final when they should be) instead of shipping such BC breaks in a minor.

Our big plans for a huge rewrite of Behat based on the cucumber pickle concept in a next major version does not need to be named 4.0. It can be a later major version number.
It is not like the ecosystem can complain that we do major versions too often. The last major version bump was in April 2014 (PHPUnit does it once per year...)

@VincentLanglet
Copy link

Oops, thanks, it should be fine now! :)

There is still a small issue here, someone from Symfony must create the tag 3.6.1 on symfony/translation-contracts, and we will be good:

  Problem 1
    - Root composer.json requires symfony/translation ^5.4 || ^6.4 || ^7.0 || ^8.0 -> satisfiable by symfony/translation[v8.0.0-BETA1].
    - symfony/translation v8.0.0-BETA1 requires symfony/translation-contracts ^3.6.1 -> found symfony/translation-contracts[dev-main, 3.6.x-dev (alias of dev-main)] but it does not match your minimum-stability.

3.6.1 was tagged @Kocal

@Kocal Kocal force-pushed the symfony-8 branch 5 times, most recently from 992eafd to 4f798cb Compare November 7, 2025 21:13
@Kocal
Copy link
Contributor Author

Kocal commented Nov 7, 2025

The PR is finally green!

Indeed, creating a new major release and marking some classes as final/internal would be much safer to prevent any potential BC in user-land.

@acoulton
Copy link
Contributor

acoulton commented Nov 7, 2025

OK, we'll get a 4.x branch going / updated for us to start working towards a (small) 4.0 - will get this merged as soon as we have something clean to merge to (the current 4.x is very out of date / essentially abandoned and we need to work out the best way to solve that - see #1692).

@acoulton acoulton changed the title Add Symfony 8 support [4.x] feat: Add Symfony 8 support Nov 20, 2025
@acoulton acoulton added this to the 4.0.0 milestone Nov 20, 2025
@acoulton acoulton changed the base branch from master to 4.x November 24, 2025 09:34
acoulton added a commit to acoulton/Behat that referenced this pull request Nov 24, 2025
Extracted from work by @Kocal in Behat#1687 - these return types will
be required in 4.x for symfony8 support, but can be added in 3.x
without any BC impact as they are either final classes or internal
test code. This will reduce potential for future conflicts merging
3.x up to 4.x.
@acoulton acoulton reopened this Nov 24, 2025
@acoulton
Copy link
Contributor

Oops - github automatically closed this when I deleted & recreated the 4.x branch. This can now be rebased.

@Kocal
Copy link
Contributor Author

Kocal commented Nov 24, 2025

Will do tonight, thanks for cherry-pickings :)

@Kocal Kocal force-pushed the symfony-8 branch 2 times, most recently from a2ad621 to da50c2c Compare November 24, 2025 20:28
@Kocal
Copy link
Contributor Author

Kocal commented Nov 24, 2025

PR rebased!

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

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

Thanks very much @Kocal just a couple of comments on the build.yml

os: ubuntu-latest
composer-mode: update
composer-minimum-stability: beta
symfony-version: '^8.0.0-BETA-1'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think with the minimum-stability set to beta, we don't need to explicitly specify it in the version constraint as well - if I install locally on this branch with SYMFONY_REQUIRE=8.0.* I'm getting the same packages as the actions run installed here.

Suggested change
symfony-version: '^8.0.0-BETA-1'
symfony-version: '8.0.*'

SYMFONY_REQUIRE: ${{ matrix.symfony-version }}.*
run: composer update ${{ matrix.php == '8.5' && '--ignore-platform-req=php+' || '' }}
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: composer update ${{ (matrix.php == '8.4' || matrix.php == '8.5') && '--ignore-platform-req=php+' || '' }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not clear on the rationale for this change. I've just tried installing locally on 8.4 with the SYMFONY_REQUIRE set to 8.0.* and I'm getting the same packages with & without the --ignore-platform-req flag.

AFAICS we only need that on 8.5 to allow us to install with dependencies that don't officially support 8.5 yet.

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

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

Great work, thanks for doing this @Kocal

@acoulton acoulton merged commit 96ae2e0 into Behat:4.x Nov 26, 2025
22 checks passed
@Kocal Kocal deleted the symfony-8 branch November 26, 2025 21:24
mpdude added a commit to mpdude/behat-fail-aid that referenced this pull request Dec 2, 2025
Symfony 8 added return types to all interfaces and classes. This leaks through the Behat API in places where Behat used classes from Symfony, for example the Event Dispatcher implementation or the `\Behat\Testwork\ServiceContainer\Extension` interface which extends `\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface`.

The Behat maintainers work on creating a new Behat release supporting Symfony 8, but it will also affect extensions like this one (Behat/Behat#1687).
@mpdude
Copy link
Contributor

mpdude commented Dec 2, 2025

Is there a list of items that need to be worked on for this minimal-changes 4.0 release?

@acoulton
Copy link
Contributor

acoulton commented Dec 3, 2025

@mpdude sort of - I have started a 4.0 milestone, with some of the existing issues that I think are relevant - but there are some things (e.g. adding strict types throughout) that still exist in our heads / in comments on other issues. I'll try to create a proper 4.0 release planning issue later today, or tomorrow.

@mpdude
Copy link
Contributor

mpdude commented Dec 3, 2025

Thank you!

I was asking because I'd like to help extension maintainers to take care of the necessary changes and make new releases compatible to a future 4.x themselves – something that I expect to take some time and that blocks some of my projects from doing "clean" Symfony 8 upgrades (without installing pending PR branches of things through Composer).

Selling changes to extension maintainers, especially when it comes to declaring compat with Behat 4 would be much easier if 4.0 were already a real thing 😉 .

Keep up the good work! It's amazing to see how much things have been moving here over the past weeks.

@stof
Copy link
Member

stof commented Dec 3, 2025

For extension maintainers, the main necessary change will be to use native types when they override/implement methods coming from Behat (and requiring at least PHP 7.2+ so that they can benefit from PHP variance rules to be compatible with both 3.x and 4.x of Behat)

@mpdude
Copy link
Contributor

mpdude commented Dec 3, 2025

Would you recommend that extension authors declare symfony/event-dispatcher and/or symfony/depencency-injection in their composer.json files with appropriate versions, since they depend on interfaces from those packages - even if that's hidden behind the Extension Behat interface that extends CompilerPassInterface?

(Yes, I have seen #1316 and I see that there might be better solutions that make the problem go away.)

@acoulton
Copy link
Contributor

acoulton commented Dec 3, 2025

I think that's probably one of the first questions we need to research/answer.

My strong preference would be for us to define our own clean interfaces (which would coincidentally be the same as the current symfony ones, but might diverge in future).

And then extension developers would not be tied to any particular symfony dependency unless they were using symfony features directly.

However it needs someone to dig in to how complex that would be to implement / support in the Behat codebase in the first instance.

@acoulton acoulton modified the milestones: 4.0.0, 4.0.0-alpha1 Dec 4, 2025
mpdude added a commit to mpdude/behat-fail-aid that referenced this pull request Dec 17, 2025
Symfony 8 added return types to all interfaces and classes. This leaks through the Behat API in places where Behat used classes from Symfony, for example the Event Dispatcher implementation or the `\Behat\Testwork\ServiceContainer\Extension` interface which extends `\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface`.

The Behat maintainers work on creating a new Behat release supporting Symfony 8, but it will also affect extensions like this one (Behat/Behat#1687).

We cannot yet tell what Behat 4 will look like and whether any other changes will be required, but this change here is a fix that can be applied as of today
shahinataei-ts added a commit to shahinataei-ts/SymfonyExtension that referenced this pull request Dec 22, 2025
The extension code already has the required return types on process() methods,
making it compatible with both Behat 3.x and 4.x interfaces.

Changes:
- Update behat/behat constraint to ^3.22 || ^4.0
- Update symfony/* dependencies to include ^8.0
- Add CI matrix entry for Symfony 8.0 with Behat 4.x-dev

Note: Symfony 8 requires Behat 4.x-dev as Behat 3.x doesn't declare
Symfony 8 compatibility in its composer.json constraints.

Relates to Behat/Behat#1687
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.

6 participants