Skip to content

Conversation

@acoulton
Copy link
Contributor

@acoulton acoulton commented Dec 7, 2025

symfony/console 7.4.0 deprecates the Application::add method in favour of a new Application::addCommand method. Application::add is then removed in 8.0.

We had a fix for this in the 4.0 branch, but it started to cause phpstan errors once symfony 8.0 was released & installed for the phpstan job. Additionally, the errors varied depending on the symfony version installed.

This fix bumps us off the deprecated method for Behat 3.x and symfony >= 7.4.0. It also updates the phpstan ignore to cover all supported symfony versions.

symfony/console 7.4.0 deprecates the `Application::add` method in favour
of a new `Application::addCommand` method. `Application::add` is then
removed in 8.0.

We had a fix for this in the 4.0 branch, but it started to cause phpstan
errors once symfony 8.0 was released & installed for the phpstan job.
Additionally, the errors varied depending on the symfony version
installed.

This fix bumps us off the deprecated method for Behat 3.x and symfony >=
7.4.0. It also updates the phpstan ignore to cover all supported symfony
versions.
- src/Behat/Testwork/Ordering/Cli/OrderController.php
-
# BC wrapper for symfony/console < 7.4.0
message: '#method_exists.+ ''(add|addCommand)'' will always evaluate to (true|false)#'
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 have intentionally left out the identifier as it varies between symfony version installed (function.impossibleType if the method is not present, function.alreadyNarrowedType if it is).

}

// Otherwise assert we are on an older version with `add` and call that.
assert(method_exists($this, 'add'));
Copy link
Contributor Author

@acoulton acoulton Dec 7, 2025

Choose a reason for hiding this comment

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

This is the main functional difference to the patch in the 4.x branch - that was just using a ternary:

method_exists($this, 'addCommand') ? $this->addCommand($command) : $this->add($command);

But of course there is no guarantee that add exists just because addCommand does not, so once 8.0 was actually released (and therefore installed in the phpstan build) it reported that the add method does not exist. Asserting here avoids that.

Copy link
Contributor

@carlos-granados carlos-granados left a comment

Choose a reason for hiding this comment

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

Makes sense

@acoulton acoulton merged commit 1d89af3 into Behat:3.x Dec 7, 2025
21 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.

2 participants