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

check if wp_is_serving_rest_request exists first #107

Closed
wants to merge 1 commit into from

Conversation

circlecube
Copy link
Member

move the logic into its own method to keep it readable

Proposed changes

Still hitting a fatal error in tests where the method is undefined. This checks if it exists before attempting to use it. Since it's only used to determine the timeout, this isn't too big a deal if the method isn't defined.

I suspect it's only being called because we're spoofing a token in our test since the solutions request bails if there's no connection. But not sure why the method would be undefined in that case, this should take care of the fatal though.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Video

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

move the logic into its own method to keep it readable
@circlecube
Copy link
Member Author

Reworked the tests so this fatal isn't showing up anymore, but this is still worth a review I think.

@circlecube circlecube self-assigned this Nov 8, 2024
@BrianHenryIE
Copy link
Contributor

BrianHenryIE commented Nov 8, 2024

wp_is_serving_rest_request() is defined in functions.php so it will always be available when WordPress is loaded.

I presume then the unit tests are failing, but where?! The correct way to mock the function is with:

WP_Mock::userFunction( 'wp_is_serving_rest_request' )
->once()
->andReturnFalse();

I would prefer not to merge this change, since it's not really a production issue, so the fix shouldn't be in production code.

And unimportant to this usage, but I believe wp_is_serving_rest_request() would return false during our bootstrap.php because REST_REQUEST is not defined until later – in rest_api_loaded() – hooked in wp-includes/default-filters.php – called during parse_request() function which I think is hooked on wp.

@circlecube
Copy link
Member Author

I was referring to the cypress tests. There was a fatal error Fatal error: Uncaught Error: Call to undefined function NewfoldLabs\WP\Module\Data\wp_is... not sure how it would be undefined though. The cypress test was running a CLI command to set a token. I've since changed the module and then the test since we didn't need to require a token just a capability.

I'm fine with closing as we have never had this issue before, this PR was troubleshooting mainly.

@circlecube circlecube deleted the fix/undefined-wp_is_serving_rest_request branch November 19, 2024 21:53
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