Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with PHPUnit 11 #4313

Closed
wants to merge 1 commit into from

Conversation

MauricioFauth
Copy link
Contributor

@MauricioFauth MauricioFauth commented Sep 12, 2024

When PHPUnit\Framework\Attributes\DataProvider attribute is found, PHPUnit ignores the @dataProvider annotation. This behavior can be used to fix compatibility with PHPUnit 11.

  • Adds static data providers for Twig\Test\IntegrationTestCase. Running PHPUnit 10+ will require Twig\Test\IntegrationTestCase::getFixturesDirectory() to be implemented.
  • Removes the Twig\Test\NodeTestCase::getTests() data provider from the DataProvider attribute. This way it doesn't get called with PHPUnit 10+ causing the tests to fail.

Related to:

- Adds static data providers for Twig\Test\IntegrationTestCase. Running
  PHPUnit 10+ will require
  Twig\Test\IntegrationTestCase::getFixturesDirectory() to be
  implemented.
- Removes the Twig\Test\NodeTestCase::getTests() data provider from the
  DataProvider attribute. This way it doesn't get called with
  PHPUnit 10+ causing the tests to fail.

Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
@stof
Copy link
Member

stof commented Sep 13, 2024

No go for this feature as it does not make tests compatible with PHPUnit 10+ if projects have not been migrated yet away from the deprecated APIs, which goes against the way deprecations should work.

If you read the discussion on #4266, you will see that support for newer PHPUnit versions in the IntegrationTestCase will be part of Twig 4.0

@stof stof closed this Sep 13, 2024
@MauricioFauth MauricioFauth deleted the phpunit-11-compat branch September 13, 2024 13:33
@MauricioFauth
Copy link
Contributor Author

@stof Would it be acceptable if tests are skipped if the method has not been implemented yet and is running PHPUnit 10+?

@MauricioFauth
Copy link
Contributor Author

MauricioFauth commented Sep 13, 2024

@stof Would it be acceptable if tests are skipped if the method has not been implemented yet and is running PHPUnit 10+?

Or skipped only for PHPUnit 11 if the method is not implemented, however that will require adding a new test method that only runs on PHPUnit 11 (no impact to the user).

@stof
Copy link
Member

stof commented Sep 13, 2024

The issue is not the test method. It is the fact that the old methods used inside the data provider were not static, so we cannot implement a static data provider that is compatible with projects that haven't migrated.

Having a changelog entry saying Add compatibility with PHPUnit 11 in IntegrationTestCase while existing usages of IntegrationTestCase are not compatible with PHPUnit 11 would be totally weird.
That's why the plan is to have this Add compatibility with PHPUnit 11 in IntegrationTestCase in Twig 4.0 instead.

@MauricioFauth MauricioFauth restored the phpunit-11-compat branch September 13, 2024 14:58
@MauricioFauth
Copy link
Contributor Author

@stof I opened a new pull request as I couldn't push to this one anymore.
The new PR does not causes an error when getFixturesDirectory is not implement and triggers a deprecation instead.

@stof
Copy link
Member

stof commented Sep 13, 2024

@MauricioFauth but even if you trigger a deprecation, this is not properly backward compatible as it does not run the expected tests (while running those tests is the expected behavior of the IntegrationTestCase)

@MauricioFauth
Copy link
Contributor Author

@stof I understand, but I don't think this is a BC break, because the expected tests don't run already. It's not like they are perfectly running before and now they don't, which is a BC break. So instead of causing errors and failing the test suite, these tests are now skipped and a deprecation is triggered, if the method is not implemented.

@stof
Copy link
Member

stof commented Sep 13, 2024

@MauricioFauth the current state of Twig is "supports PHPUnit 10 and lower for IntegrationTestCase", not "supports PHPUnit 11 without running test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants