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

Tests/remove network dependent #3541

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Conversation

adekbadek
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Removes and adjusts unit tests, so they are not network-dependent. Unit tests should not rely on remote services and servers.

How to test the changes in this Pull Request:

  1. Observe the tests are passing on CI and locally

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@adekbadek adekbadek added the [Status] Needs Review The issue or pull request needs to be reviewed label Nov 12, 2024
@adekbadek adekbadek requested a review from a team as a code owner November 12, 2024 09:36
@@ -85,159 +82,6 @@ public function test_get_plugins_authorized() {
$this->assertEquals( $expected_jetpack_info, $data['jetpack'] );
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

afaik, all these tests are not making any requests. server->dispatch is emulating the server receiving a request

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the way to test Rest API endpoints without needing http requests

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not about testing the REST API endpoints. The endpoint handler is making requests to the plugin repository to fetch plugin code.

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha

'Emails are empty until configured.'
);
self::assertFalse(
Emails::can_send_email( 'test-email-config' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we short circuit wp_mail to make sure no requests are made?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not about wp_mail. The issue with this test is that it installed newspack-newsletters from the plugin repository. I've replaced it with a mock of Newspack_Newsletters class, and to simplify removed the test assertions related to the plugin being inactive. This is not ideal, I know, but I don't think making it ideal is worth the effort.

@adekbadek adekbadek requested a review from leogermani November 13, 2024 09:11
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Nov 13, 2024
@adekbadek adekbadek merged commit 340fcb5 into trunk Nov 14, 2024
15 checks passed
Copy link

Hey @, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to it to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

@adekbadek adekbadek deleted the tests/remove-network-dependent branch November 14, 2024 08:47
@matticbot
Copy link
Contributor

🎉 This PR is included in version 5.8.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 5.8.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants