Development

To develop for ElasticPress you will need a local development environment (the same you would use to work on a WordPress site) and an Elasticsearch instance — either directly installed in your machine, a docker container, or a remote ES instance.

Local Development Environment

You can use any development tool, like Local, for example. Then, make sure you have Elasticsearch running somewhere (feel free to use our end-to-end tests environment as inspiration.)

After you have everything up and running, follow the plugin installation instructions.

In your wp-config.php file, insert the following to tell ElasticPress where Elasticsearch is located:

define( 'EP_HOST', 'http://host.docker.internal:8890' );

Finally, run composer install in the root of the plugin.

ElasticPress uses unit tests via the WordPress core unit testing library as well as end-to-end tests with Cypress.

To run unit tests, navigate to the root of the ElasticPress directory, first set up the test database:

composer run-script setup-local-tests

Now run the tests:

EP_HOST="http://host.docker.internal:8890" phpunit

To run a specific test, pass the --filter parameter:

EP_HOST="http://host.docker.internal:8890" phpunit --filter=testSanitizeCredentials

To verify all of the code paths are being tested, you can generate an HTML code coverage report for your tests. Pass --coverage-html test-coverage-html as a parameter and a report will be generated in that directory.

EP_HOST="http://host.docker.internal:8890" phpunit --filter=testSanitizeCredentials --coverage-html test-coverage-html

To run e2e tests follow these instructions.