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: LegacyProxy::get_instance_of throws when trying to get an instance of a non-Woo namespaced class #45178
Conversation
of a class with a namespace that doesn't start with 'Automattic\WooCommerce'.
Hi @lsinger, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: 9426278
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good and tests as intended. The exception is now covered by unit tests in both positive and negative cases: a test fails if it's thrown when it shouldn't be, and a test fails if it's not thrown when it should be. LGTM! 🚢
@Konamiman I edited your PR description to a) generate a changelog file and b) address an omission in the fizz.php test code that was unrelated to the problem that was solved but generated an error on the site frontend. The latter I did just to make sure that if we look at this again in the future, the test code doesn't throw any unexpected errors. Because I made those edits I'm going to let you check them and merge the PR yourself instead of merging it directly. |
…ce of a non-Woo namespaced class (#45178)
* Fix: LegacyProxy::get_instance_of throws when trying to get an instance of a non-Woo namespaced class (#45178) * Prep for cherry pick 45178 --------- Co-authored-by: Néstor Soriano <konamiman@konamiman.com> Co-authored-by: WooCommerce Bot <no-reply@woo.com>
…ce of a non-Woo namespaced class (#45178)
Changes proposed in this Pull Request:
The
get_instance_of
method of theLegacyProxy
class isn't intended to retrieve instances of classes that live in thesrc
directory (the dependency injection container should be used for these instead), and will throw an exception if that is attempted. However, in order to check if it should throw it just checks if the class name has a namespace; this will cause a false positive for namespaced classes defined outside of WooCommerce.This pull request fixes this: the method will throw only if the full class name starts with
Automattic\WooCommerce\
.How to test the changes in this Pull Request:
The bug was discovered after merging #44833: there are plugins that register namespaced REST API controllers and cause the exception. Thus for testing the fix we'll use the following code:
To setup this code:
fizz.php
file in the root directory of the plugin, and add the following at the end of thewoocommerce.php
file:include __DIR__ . '/fizz.php';
Once the code is prepared, run the following in the command line (or perform the equivalent request with Postman or a similar tool):
"Buzz!"
.Changelog entry
Significance
Type
Message
Fix LegacyProxy::get_instance_of throwing an error when trying to get an instance of a non-Woo namespaced class.
Comment