-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add feature tests for checking plugin with addon enabled #518
Conversation
ernilambar
commented
Jul 11, 2024
- Add feature tests with addon enabled (which includes new category and extra checks under that category)
Note: Behat tests are passing in my local setup with following specs.
|
Problem I am facing is classes on main plugin are not loading in the addon. Since WordPress not necessarily loads plugin files in our required order, how can I make sure that all classes of main plugin are available in the addon? CC @swissspidy |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
May be we should also add instructions in our docs on how to create addon for Plugin Check. |
Yeah simply defining the classes like that would be error prone. First, you'll want to use the Second, I would recommending moving the classes to separate files and then load them only when needed and when you know the parent classes exist. For example like so: add_filter(
'wp_plugin_check_checks',
function ( array $checks ) {
require_once './class-prohibited-text-check.php';
require_once './class-postsperpage-check.php';
return array_merge(
$checks,
array(
'prohibited_text' => new Prohibited_Text_Check(),
'postsperpage' => new PostsPerPage_Check(),
)
);
}
); |
Yeah @davidperezgar brought that up too. First we can start small, explaining the filters and giving a short example. We can reuse some of the code you're writing here for that. Not really urgent though, as I doubt there is huge demand for writing those 😄 |
Yes! That would be very helpful. |
8f74139
to
3259602
Compare
When I |
That sounds odd 🤔 Sounds like some debugging is in order |
3259602
to
697526f
Compare
@swissspidy I tried this to reproduce this in separate setup. After first command run, those checks are not included until I delete file |
So it's an issue with Plugin Check / the Want me to take a look at it to see if I can find the issue, or what's the next step? |
Yes, it does not seem to be related to Behat test. I tried to debug but could not find the exact issue. May be you can give a shot to find issue quicker as you are more familiar with the architecture 😊 |
Well, I'm not that familiar with that part 😅 The gist is that From what I can see, this hack is used so we can perform runtime checks for a plugin without the plugin having to be active on the site. But not entirely sure. When I activate Related: #153 |
I removed |
It's still needed and used by |
Behat tests are not passing. |
Yes. See #518 (comment) above and related conversation. That needs to be fixed first. |
@swissspidy @ernilambar I've been looking through the codebase a bit more to find potential problems, and so far I believe I found at least one, in
In other words, I think for CLI we either need to reduce this to just I don't know if this bug is related to the failure here, but it's worth hacking it in temporarily to try. If that's it, I think we should open a separate PR to address the bug. I think a clean implementation would be to replace the current Let me know if you have any questions. FWIW I'm thinking it might be useful to make a flowchart of how this works in the different circumstances to make it easier to follow. |
Yeah as you can see, neither @ernilambar nor I are really familiar with that flow as it's not really documented and hard to follow. If someone from the original implementers group can do that, this would be helpful. tbh, I really wish all this magic wasn't needed, and that we could address #153 instead and can come up with a simpler solution for things like the GitHub Action where it's a controlled environment. |
Could you perhaps make those changes against this PR yourself? That way it's easier to follow. |
It could have a different name
I just pushed some changes to make the tests easier to reason about. Also included a runtime check in the example add-on so we can verify those work too (they don't). We'd need to figure out how we could possibly load an add-on in CLI when doing runtime checks. Maybe the add-ons to load need to be explicitly passed as an arg or something? |
@swissspidy @ernilambar Please review #597, which is about documenting all the current process flows. While doing that, I identified a number of problems (mostly related about addon checks indeed). I believe with the additional context from that documentation (potentially after a few reviews to clarify things more), we can collaborate in finding solutions to these problems. |
Proposed next steps:
|
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.
LGTM, just minor notes.
if ( CLI_Runner::is_plugin_check() ) { | ||
if ( ! file_exists( ABSPATH . 'wp-content/object-cache.php' ) ) { |
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.
In principle, this should only be placed if runtime checks are run. If only static checks should be run against a plugin, this isn't needed. But I'm not sure it's reasonably possible to detect that from here.
FWIW at the moment users of WP-CLI have to know about the --require
portion anyway, so because of that it's probably okay to also expect of them to only include the --require
if they want to run any runtime checks. Something to improve elsewhere, as we've already discussed a few times.