Skip to content
Thomas Steur edited this page Jul 23, 2021 · 4 revisions

Preparation

  • 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 example 5.0

Running tests

  • 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

Running PHPCS tests

  • vendor/bin/phpcs -v

Autofix some PHPCS errors/warnings

  • vendor/bin/phpcbf

Travis

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.

FAQs

How do I configure a test to only run for multisite?

You can add the following group to a test class or test method:

/**
  * @group ms-required
  */
public function test_foo() {}

What do I do if the test result is different for regular WP test and MultiSite test?

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() );
		}
	}