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

Internal: Fix PHPUnit deprecated prophecy integration #3190

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

tbsiqueira
Copy link
Contributor

@tbsiqueira tbsiqueira commented Oct 31, 2022

Problem

PHPUnit deprecated prophecy integration on sebastianbergmann/phpunit#4141

Solution

There a couple of approaches, all suggested on the above PR:

Whatever the method, unit tests should still work.

Issue tracker

N/A

Theme issue tracker

N/A

How to test

  • Make sure unit tests are still working.

Definition of done

Before merge

  • Code/peer review is completed
  • All commit messages are clear and clean. If applicable a rebase was performed
  • All automated tests are green
  • Functional/manual tests of the acceptance criteria are approved
  • All acceptance criteria were met
  • New features or changes to existing features are covered by tests, either unit (preferably) or behat
  • Update path is tested. New hook_updates should respect update order, right naming convention and consider hook_post_update code
  • Module can be safely uninstalled. Update/implement hook_uninstall and make sure that removed configuration or dependencies are removed/uninstalled
  • This pull request has all required labels (team/type/priority)
  • This pull request has a milestone
  • This pull request has an assignee (if applicable)
  • Any front end changes are tested on all major browsers
  • New UI elements, or changes on UI elements are approved by the design team
  • New features, or feature changes are approved by the product owner

After merge

  • Code is tested on all branches that it has been cherry-picked
  • Update hook number might need adjustment, make sure they have the correct order
  • The Drupal.org ticket(s) are updated according to this pull request status

Screenshots

N/A

Release notes

N/A

Change Record

N/A

Translations

N/A

@mergeable
Copy link

mergeable bot commented Oct 31, 2022

Thanks for contributing towards Open Social! A maintainer from the @goalgorilla/maintainers group might not review all changes from all teams/contributors. Please don't be discouraged if it takes a while. In the meantime, we have some automated checks running and it might be that you will see our comments with some tips or requests to speed up the review process. 😊

@tbsiqueira tbsiqueira added status: needs review This pull request is waiting for a requested review type: dependencies Updating a dependency file prio: critical team: guardians labels Oct 31, 2022
@tbsiqueira tbsiqueira force-pushed the internal/remove-deprecated-methon-on-phpunit branch from 643f82a to 47517e6 Compare October 31, 2022 09:35
Comment on lines +69 to +71
protected function tearDown(): void {
$this->prophet->checkPredictions();
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it a good idea to do this in tear down rather than on a per-test basis? I'm not sure how reporting will differ ("There was an error in cleaning up" vs "Your test failed").

I.e. the underlying question is: Does PHPUnit already consider the test case a success if it performs tearDown? If the answer is yes, we should move this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Alexander,

Is it a good idea to do this in tear down rather than on a per-test basis? I'm not sure how reporting will differ ("There was an error in cleaning up" vs "Your test failed").

According to https://phpunit.readthedocs.io/en/9.5/fixtures.html#fixtures setUp() and tearDown() template methods are run once for each test method (and on fresh instances) of the test case class. and Example Example 4.2 has a nice explanation on how they work.

I.e. the underlying question is: Does PHPUnit already consider the test case a success if it performs tearDown? If the answer is yes, we should move this.

According to official documentation from prophecy tearDown() is where we should call checkPredictions()
Please check here for more information: https://github.com/phpspec/prophecy#predictions

Copy link
Member

Choose a reason for hiding this comment

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

If official documentation says it, then that's good enough for me 👍

@tbsiqueira tbsiqueira merged commit 90c1986 into main Oct 31, 2022
@tbsiqueira tbsiqueira deleted the internal/remove-deprecated-methon-on-phpunit branch October 31, 2022 14:02
@tbsiqueira tbsiqueira added this to the 11.5.0-rc1 milestone Nov 1, 2022
@tbsiqueira
Copy link
Contributor Author

Cherry-picked to 11.5.x here 5c464c4

@tbsiqueira tbsiqueira added the backport: verified This pull request has been back ported to an older minor version label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport: verified This pull request has been back ported to an older minor version prio: critical status: needs review This pull request is waiting for a requested review team: guardians type: dependencies Updating a dependency file
Development

Successfully merging this pull request may close these issues.

2 participants