-
-
Notifications
You must be signed in to change notification settings - Fork 25
Tests
Thomas Steur edited this page Jul 23, 2021
·
4 revisions
- Install composer
- cd into the matomo plugin directory, eg
cd wp-content/plugins/matomo
- Run
composer install
- Install the test DB
bin/install-wp-tests.sh <db-name> <db-user> <db-password> [db-host] [wp-version] [skip-database-creation]
- For example
./bin/install-wp-tests.sh wordpress_test root secure 127.0.0.1 latest
- To run tests against an older WordPress version replace
latest
with for example5.0
- For example
- Run all the tests by executing
vendor/bin/phpunit
- Run a specific test by executing
vendor/bin/phpunit tests/phpunit/wpmatomo/test-settings.php
- Run tests for multi site prefix the tests with
WP_MULTISITE=1 vendor/bin/phpunit
vendor/bin/phpcs -v
vendor/bin/phpcbf
We execute all tests once using phpunit
.
Then we execute all tests again for multisite by using WP_MULTISITE=1
.
This is done here.
Sometimes a test might only fail for a regular WP install or MultiSite install.
You can add the following group to a test class or test method:
/**
* @group ms-required
*/
public function test_foo() {}
Either it indicates a bug and you need to change the application logic. If a different return value is expected then you can adjust the expected value in the tests like this:
public function test_get_tmp_dir() {
if ( is_multisite() ) {
$this->assertSame( get_temp_dir() . 'wordpress/wp-content/uploads/matomo/tmp', $this->paths->get_tmp_dir() );
} else {
$this->assertSame( get_temp_dir() . 'wordpress/wp-content/cache/matomo', $this->paths->get_tmp_dir() );
}
}