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

Separate plugin functionality into separate classes #3

Merged
merged 4 commits into from
Sep 20, 2024

Conversation

nickpagz
Copy link
Owner

@nickpagz nickpagz commented Jan 14, 2023

Purpose for this PR:

This PR is intended to capture changes to the plugin's structure to follow WordPress best practices. No plugin functionality changes are included. In order to ensure the refactoring doesn't introduce errors, unit tests are also introduced to check functionality remains as intended.

Changes:

  • The first commit includes scaffolding in PHPUnit and the extended WP_UnitTestCase, and some very basic tests to check functionality.
  • The second commit added an additional factory for the job_listing CPT, borrowed from WP Job Manager, tweaked tests, and the restructure of the main class into two separate classes. One class handles the settings, and the other the output.
  • The third commit includes a minor tweak to add an option for the feed items count to improve a couple of the existing tests.

Still to be added:

  • Unit/integrated tests for checking the output is a standard xml feed, contains the correct structure and elements, and outputs the correct number of feed items.

Unit Testing:

  • From the plugin root directory run composer install to include the PHPUnit dependencies.
  • Install the WP tests using the format ./bin/install-wp-tests.sh <database-name> <database-user> <database-password> [<database-host>]. Example: ./bin/install-wp-tests.sh wordpress_tests root root localhost latest, noting your user and password may depend on your local sql credentials.
  • Since this uses PHPUnit 9.5+, the testing command needs to explicitly called a name testsuite, so use the following command to run the unit tests from the plugin root folder: vendor/bin/phpunit --testsuite tests.

Adding tests as a pre-cursor to refactoring classes to meet SRP.

Tests are implemented using the latest PHPUnit version (9.5.x) and can be run as follows:
From the plugin root folder, first install dependencies with composer, ie "composer install".
The install the WP tests based on the following command. `bin/install-wp-tests.sh <db-name> <db-user> <db-pass>
[db-host] [wp-version] [skip-database-creation]`. For example, `bin/install-wp-tests.sh wordpress_tests root root localhost latest` should
work.
Use the following to run all tests:
`vendor/bin/phpunit --testsuite tests`
This commit helps to separate functionality by separating the original class file into two separate files and classes, one for settings, and
one for the output.
Some additional code clean-up is included, such as removing the init type functions, such as add_actions, out of the construct.
Also added some extended factory code for supporting the job_listing CPT for future integration testing.
The previous commit was missing an "add_option" in the set_up() for unit tests. This commit adds the option, fixed the tests to check for the
default value, then deletes the option in the tear_down() method.
@nickpagz nickpagz merged commit 5c71eaa into master Sep 20, 2024
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.

1 participant