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

Setup Unit tests #28

Merged
merged 42 commits into from
Sep 21, 2022
Merged

Setup Unit tests #28

merged 42 commits into from
Sep 21, 2022

Conversation

renatonascalves
Copy link
Contributor

@renatonascalves renatonascalves commented Aug 17, 2022

  • Bootstrap unit test
  • Create a basic unit test case
  • Add GH Action to test adapters per action
  • Use Pest
  • Fix PHPCS issues

Pest will inform the available adapters:

...
Running as single site...
ℹ️  To run multisite, pass WP_MULTISITE=1 or set the WP_TESTS_MULTISITE=1 constant.
----
Elasticsearch is up and running, using version: 7.[17]
-- The SearchPress plugin is available! \o/
-- The VIP Enterprise Search plugin is available! \o/
----

Here is how one can run tests per adapter:

VIP Search Adapter

phpunit --testsuite=vip-search
phpunit --group=vip-search

SearchPress Adapter

phpunit --testsuite=searchpress
phpunit --group=searchpress

Note: the recommendation is to use the --testsuite param since one can forget to add the --group to a new unit test file.

@renatonascalves renatonascalves self-assigned this Aug 17, 2022
Copy link
Member

@srtfisher srtfisher left a comment

Choose a reason for hiding this comment

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

💯

composer.json Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
* @subpackage Tests
*/

it( 'should load the SP version', function () {
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 so cool to see, very glad you kept at it!

tests/bootstrap.php Outdated Show resolved Hide resolved
renatonascalves and others added 3 commits August 19, 2022 16:26
Co-authored-by: Sean Fisher <[email protected]>
Co-authored-by: Sean Fisher <[email protected]>
Co-authored-by: Sean Fisher <[email protected]>
@renatonascalves
Copy link
Contributor Author

@kevinfodness Could you update the branch settings with the new Github Actions?

@kevinfodness
Copy link
Member

@renatonascalves branch protection rules have been updated.

@@ -15,6 +15,9 @@
use Elasticsearch_Extensions\Controller;
use Elasticsearch_Extensions\Registry;

// Load Composer dependencies.
require_once __DIR__ . '/vendor/wordpress-autoload.php';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how people are adding/installing this plugin but I'd assume this change would break their sites (in case they pull directly from GitHub).

Copy link
Member

Choose a reason for hiding this comment

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

How would it break their sites? Because they need to run composer install on it?

It should be installed as a plugin via composer, although it could be submoduled, but in any case, needing to run composer install on it is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! Thanks for the confirmation.

But yes, my concern was a site could be using the plugin without using composer. Pulling the latest would cause a fatal error since the vendor folder would not exist.

Copy link
Member

Choose a reason for hiding this comment

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

If we ever get around to publishing this on WordPress.org we will add a step that installs the vendor folder and includes that in what is sent to the WP.org SVN repo (as well as removing some development files that wouldn't be needed in a production install). But for now it's fine to leave as-is. You might want to add a note in the README about needing to run composer install if that's not there already.

Copy link
Member

@kevinfodness kevinfodness left a comment

Choose a reason for hiding this comment

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

This looks good to me—thanks for putting this together. I'm sure we'll iterate on it as we get into writing tests, but this is a great starting point and enables us to be able to start writing tests for our adapters. 🍣

"wpackagist-plugin/elasticpress": "^4.2",
"yoast/phpunit-polyfills": "^1.0"
},
"scripts": {
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
"phpunit": "phpunit",
"phpunit": "@test",
Copy link
Member

Choose a reason for hiding this comment

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

Don't bother aliasing this, just run composer test. That will need to be updated in the GitHub actions for tests as well, if it isn't already.

@@ -15,6 +15,9 @@
use Elasticsearch_Extensions\Controller;
use Elasticsearch_Extensions\Registry;

// Load Composer dependencies.
require_once __DIR__ . '/vendor/wordpress-autoload.php';
Copy link
Member

Choose a reason for hiding this comment

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

How would it break their sites? Because they need to run composer install on it?

It should be installed as a plugin via composer, although it could be submoduled, but in any case, needing to run composer install on it is fine.

<directory prefix="test-vip-search" suffix=".php">./tests/adapters/vip-search/</directory>
</testsuite>

<testsuite name="plugin">
Copy link
Member

Choose a reason for hiding this comment

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

I like this - a way to run generic tests and also tests for specific adapters.

'pre_option_upload_path',
function () {
return ABSPATH . 'wp-content/uploads';
define( 'ELASTICSEARCH_EXTENSIONS_TESTS_DIR', dirname( __DIR__ ) . '/tests/' );
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 really just __DIR__. Rather than establishing a separate constant here, I'd rather just use __DIR__ below.

Mantle\Testing\manager()
->before( function() {
// Define bootstrap helper functions.
require_once ELASTICSEARCH_EXTENSIONS_TESTS_DIR . '/includes/bootstrap-functions.php';
Copy link
Member

Choose a reason for hiding this comment

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

Example:

Suggested change
require_once ELASTICSEARCH_EXTENSIONS_TESTS_DIR . '/includes/bootstrap-functions.php';
require_once __DIR__ . '/includes/bootstrap-functions.php';

@kevinfodness kevinfodness merged commit 7c3f89b into main Sep 21, 2022
@kevinfodness kevinfodness deleted the feature/setup-unit-tests branch September 21, 2022 15:32
@kevinfodness
Copy link
Member

@renatonascalves I merged this because the config for required status checks on other PRs expects the status checks defined here. If you'd like to implement my suggestions from code review, you can do so in a separate PR. Thanks again for putting these tests together!

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.

3 participants