-
Follow these instructions to install VVV.
-
Open
config/config.yml
. -
In the
wordpress-trunk
sites entry, setskip_provisioning
tofalse
. -
Run
vagrant up --provision
. -
Enter
vagrant ssh
to SSH into the machine that's running your Sensei site. -
Execute
cd /srv/www/wordpress-one/public_html/wp-content/plugins/sensei
(location may vary depending on which directory Sensei is in). -
Install the tests:
$ tests/bin/install_vvv.sh
The following instructions should work on Linux and macOS. If you want to run the tests on Windows please see this guide and the instructions on using Varying Vagrant Vagrants above.
To run the tests locally, you will need the following:
- Composer.
- A MySQL database.
Do not use an existing database or you will lose data. To install a database locally, there are two options.
- Install docker by following the instructions here.
- Run
docker run --name mysql_57 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=<test_db_name> -e MYSQL_USER=<test_user_name> -e MYSQL_PASSWORD=<test_user_password> --rm -d mysql:5.7
The above will start a MySQL server container and create a database with the specified name and a user with the supplied username and password. To stop the container you can use docker container stop mysql_57
.
To install MySQL follow the instructions provided here.
To install the WP test suite you need to first run composer install
and npm install
in the top level directory. Then you need to use the tests/bin/install-wp-tests.sh
script to install the WP test suite.
install-wp-tests.sh
script needs svn
to be installed in order to create test files. You can find instructions for installing svn
here.
If you used Docker to create a database, you need to pass the database name and the user credentials from the previous step. You also need to skip creating a new database:
TMPDIR=/tmp ./tests/bin/install-wp-tests.sh <test_db_name> <test_user_name> <test_user_password> 127.0.0.1 latest true
If you used MySQL Server you need to supply the values for the new database only:
TMPDIR=/tmp ./tests/bin/install-wp-tests.sh <test_db_name> <test_user_name> <test_user_password>
To run both PHPUnit and Jest tests you can use the following command in the plugin root directory:
$ npm run test
If you are interested in PHPUnit tests only, you can use the following:
$ npm run test-php
If you are interested in Jest tests only, you can use the following:
$ npm run test-js
You can run specific tests by providing the path and filename to the test class. For example:
$ npm run test-php tests/unit-tests/test-class-admin
- Each test file should roughly correspond to an associated source file, e.g. the
test-class-woothemes-sensei.php
test file covers code inclass-woothemes-sensei.php
. - Each test method should cover a single method or function with one or more assertions.
- A single method or function can have multiple associated test methods if it's a large or complex method.
- Prefer
assertSame()
where possible as it tests both type & equality. - Remember that only methods prefixed with
test
will be run. - Filters persist between test cases so be sure to remove them in your test method or in the
tearDown()
method.