-
Notifications
You must be signed in to change notification settings - Fork 50
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
Feature/updated autoloading #236
base: trunk
Are you sure you want to change the base?
Conversation
bin/install-wp-tests.sh
Outdated
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 is an updated version of the default install-wp-tests.sh
, it has a few benefits:
- It has a help command, which ensures engineers that are new to PHPUnit have a way to understand the params of the script
- When run from a Local WP shell, it automatically picks up and uses the MySQL socket.
It has a sensible set of defaults that will work for 99% of 10up builds, meaning you can run the script without passing any parameters. - It resolves an issue where the install script thinks it's already installed (because the
/tmp
directory exists, but the DB isn't installed.
$method = $class->getMethod( 'get_classes' ); | ||
|
||
$classes = $method->invoke( $this->class ); | ||
$this->assertCount( 2, $classes ); |
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.
I think this should be a count greater than 1. If it can find 1 then it's working. Otherwise you need to update this test every time you include another class.
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.
Good call, I had this on a project that I'm using this on. I'll update with the tests I'm using there!
# Conflicts: # .github/workflows/php.yml # composer.json # composer.lock # mu-plugins/10up-plugin/composer.json # mu-plugins/10up-plugin/composer.lock # themes/10up-theme/composer.json # themes/10up-theme/composer.lock
# Conflicts: # .github/workflows/php.yml # docs/registering-classes.md # mu-plugins/10up-plugin/composer.lock # themes/10up-theme/composer.lock
42501f6
to
ab307d3
Compare
Description of the Change
This PR updates the class autoloader from using https://gitlab.com/hpierce1102/ClassFinder/ to using https://github.com/spatie/php-structure-discoverer and adds unit tests to ensure it's working as expected.
Spatie are a well known company, who specialise in Open Source packages. This means the package is updated more often and bugs will be fixed more quickly. For example, the last commit in
hpierce1102/classfinder
was June 18, 2023, whereas the last commit inspatie/php-structure-discoverer
was today.There are a few other benefits of the Spatie package:
composer.json
to load files, meaning we no longer have to deploy that.Old Class Loader
New Class Loader
Additionally, during the refactor, I eliminated all the hardcoded strings and awkward configurations needed to get the classloader working. It should now be plug-and-play.
One downside of this change is that it only supports PHP 8.1 upwards, though since every version pre-8.1 is End of Life, I think that's a fair tradeoff, https://www.php.net/supported-versions.php.
How to test the Change
Ensure all classes are still loading and test suite is passing.
Changelog Entry
Credits
Props @darylldoyle
Checklist: