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 tests to run in same process #565

Merged
merged 3 commits into from
Oct 9, 2018

Conversation

joshcanhelp
Copy link
Contributor

Changes

Changed the test runner to run in the same process, speeding tests up by a lot.

References

PHPUnit annotations

Testing

Changes to test suite only.

Checklist

  • All existing and new tests complete without errors
  • All code quality tools/guidelines in the Contribution guide have been run/followed
  • All active GitHub CI checks have passed

@joshcanhelp joshcanhelp added this to the 3.8.0 milestone Oct 8, 2018
@@ -73,14 +72,14 @@ public function admin_enqueue_scripts() {
WPA0_VERSION
);

$profile = get_auth0userinfo( $user_id );
$profile = get_auth0userinfo( $GLOBALS['user_id'] );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Different way to access globals in PHP, works better for testing.


if ( ! current_user_can( 'edit_users', $user_id ) ) {
if ( ! isset( $GLOBALS['user_id'] ) || ! current_user_can( 'edit_users', $GLOBALS['user_id'] ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Different way to access globals in PHP, works better for testing.

global $user_id;
if ( ! current_user_can( 'edit_users', $user_id ) ) {

if ( ! isset( $GLOBALS['user_id'] ) || ! current_user_can( 'edit_users', $GLOBALS['user_id'] ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Different way to access globals in PHP, works better for testing.

@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
backupGlobals="true"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep the global vars the same between tests

@@ -39,6 +39,8 @@ class TestConstantSettings extends TestCase {

/**
* Test that setting a constant will store the constant key.
*
* @runInSeparateProcess
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Separate process required here because constants are set (cannot be unset)

@auth0 auth0 deleted a comment from codecov-io Oct 8, 2018
@cocojoe
Copy link
Member

cocojoe commented Oct 9, 2018

@joshcanhelp Why is it better for testing? Shouldn't both methods to access a Global give the same results?

@joshcanhelp
Copy link
Contributor Author

@cocojoe - They do in practice but while testing, it was causing issues, possibly with how PHPUnit backs them up between tests.

@cocojoe
Copy link
Member

cocojoe commented Oct 9, 2018

I wondered if it had to do with that, the one off use in a method is probably clearer than using global xxx.
In PHP docs both methods are legit.

Copy link
Member

@cocojoe cocojoe left a comment

Choose a reason for hiding this comment

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

👍

@joshcanhelp joshcanhelp merged commit 12909d2 into master Oct 9, 2018
@joshcanhelp joshcanhelp deleted the fix-tests-to-run-in-same-process branch October 9, 2018 16:23
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants