Skip to content

Adds enum unit tests #26

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

Merged
merged 20 commits into from
Jul 23, 2025
Merged

Adds enum unit tests #26

merged 20 commits into from
Jul 23, 2025

Conversation

JasonTheAdams
Copy link
Member

Depends on #25

This adds the PHPUnit infrastructure and the unit tests for the enums from #25. It also adds a Github workflow to run the unit tests for pull requests and pushes.

@JasonTheAdams JasonTheAdams self-assigned this Jul 18, 2025
@JasonTheAdams JasonTheAdams requested a review from felixarntz July 21, 2025 19:22
Base automatically changed from feature/initial-enums to trunk July 22, 2025 23:08
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams Thanks, this looks great!

Just a few small details I think we may want to revise. But overall almost good to merge.

Nit-pick: Could you avoid prefixing PR branches with feature/? The idea (relevant e.g. for php-lint.yml) is that that prefix should only be used for feature branches - i.e. branches where a new larger feature is being developed across several PRs separate from trunk.

runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.4']
Copy link
Member

Choose a reason for hiding this comment

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

This is a pragmatic start, although I'm wondering whether we should at least cover one in between, e.g. 8.0?

WordPress even tests all versions, and while that might be excessive for this project, maybe there is a middle ground?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've never personally understood the reason for that. In my mind if it's compatible with 8.4 then it's compatible with each step between. I guess an argument could be made that it will show at exactly which version something is breaking... but that feels like a moot point if the goal is to be compatible all the way up to 8.4. We've done it this way in a handful of our plugins for years with no noticeable downside.

That said, it's really not a big deal, so I'm happy to add it if you still feel it's best. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Usually what you're saying is right. But there can always be nuances between versions in little things we wouldn't foresee, and for a project as big as WordPress Core, I think it's worth going for the always - in other words, test with every PHP version to do the closest possible in detecting any possible errors, even if unlikely.

This SDK is obviously not the same reach/scale, so no need to do it here, but I do think one version in between would be helpful, also to get a better idea when/where something broke. This will make finding the root and fixing the bug faster for us too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sound reasoning. Thanks for walking me through that. I've resolved this by adding 8.0 in d5bdb61

@@ -0,0 +1,17 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

Is it a common pattern in PHP projects to have mock files or utility classes for testing colocated between all the actual tests?

If so, I'd be okay with that, but based on what I'm used to from WordPress, I'd consider this a bit messy. An alternative would be to separate tests/unit/tests from tests/unit/lib or something like that. Then the first would only contain actual tests.

Curious what you think. Have you seen the pattern here in other popular PHP projects?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought about that. I actually meant to circle back, as I don't like colocation because it breaks the 1-to-1 pattern of src to the unit tests. The pattern I've liked is tests/mocks, so I'll start with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tentatively resolved in fbc4501. Open to your thoughts!

@felixarntz felixarntz mentioned this pull request Jul 17, 2025
15 tasks
@JasonTheAdams JasonTheAdams requested a review from felixarntz July 23, 2025 00:57
@JasonTheAdams
Copy link
Member Author

I resolved most of your feedback, @felixarntz, and left some comments!

Funny on the branch naming. I think of feature branches as a unit of work introducing a feature or portion thereof. I've used epic branches (epic/) for joint bits of work that aren't considered deliverable until collectively completed. Totally happy to adapt for this project, though! Lots of ways to work. 😄

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams Thanks, tentatively approving this with minor feedback, see below.

I think breaking out the mocks into their own directory makes sense. In the future we may also need other infra test classes that aren't mocks, but no need to cater for that now, as we don't know.

My one suggestion would be to organize the nesting of the directories as follows:

  • tests/unit/tests
  • tests/unit/mocks

The reason for that is that unit tests are one type of tests, and there could be others we may eventually implement. Currently, tests/mocks is outside of tests/unit, although it also relates exclusively to unit tests.

Alternatively, if we prefer not to have the extra nesting, we could for now decide to consider the entire tests directory exclusively for unit tests. In that case, I'd suggest to give the tests/unit directory another name, as the overarching tests directory as a whole would be for unit tests overall, and what's called unit here would contain the actual tests. Let me know what you prefer.

@felixarntz
Copy link
Member

After a quick DM chat with @JasonTheAdams, we aligned on keeping the tests organized as currently is - works for now. 👍

@felixarntz felixarntz merged commit 61362ef into trunk Jul 23, 2025
7 checks passed
@JasonTheAdams JasonTheAdams deleted the feature/unit-tests branch July 23, 2025 22:14
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