Skip to content

Running tests

Andrey Savchenko edited this page Oct 28, 2015 · 9 revisions

Running the WordPress SEO Test Suite

WordPress SEO is using Travis CI to run its tests after every commit. Should you want to run the WordPress SEO in your local development area you can take the following steps.

Running via command line

Installation

Make sure you have Composer and PHPUnit installed.

  1. Set up the WordPress core test environment, following Automated Testing instructions in the Core Handbook
  2. Set up the development copy of the plugin, following setting up development copy instructions in the wiki
  3. Run composer config-yoastcs in the plugin's directory to set up PHP Code Sniffer settings.

Execution

The following commands should now be used in plugin's directory:

  • phpunit -c phpunit.xml will run unit tests
  • vendor/bin/phpcs will run code style check

Running via PhpStorm

PHPUnit

  1. Set up PHPUnit support, following instructions in documentation.
  2. Create new run configuration via: Run > Edit Configurations > Add New Configuration > PHPUnit
  3. Set Test Scope to Defined in the configuration file
  4. Enable Use alternative configuration file and point to wordpress-seo/phpunit.xml file location
  5. Save configuration
  6. Run configuration via Run menu

PHPUnit with code coverage

  1. Follow instructions for normal PHPUnit setup
  2. Make sure you have Xdebug PHP extension enabled with xdebug.coverage_enable and xdebug.extended_info
  3. Run configuration via Run menu > Run [configuration name] with coverage...

PHP Code Sniffer

  1. Configure Settings > Languages & Frameworks > PHP > Code Sniffer > PHP Code Sniffer (phpcs) path to point to vendor/bin/phpcs in the plugin.
  2. Enable Settings > Editor > Inspections > PHP > PHP Code Sniffer validation
  3. Set Severity to Error
  4. Set Show warning as to desired level
  5. Set Coding standard to Yoast (make sure you had run composer config-yoastcs before this)

You will see results inline, together with other inspections.

PHP Mess Detector

  1. Configure Settings > Languages & Frameworks > PHP > Mess Detector > PHP Mess Detector (phpmd) path to point to vendor/bin/phpmd in the plugin.
  2. Enable Settings > Editor > Inspections > PHP > PHP Mess Detector validation
  3. Set Severity to desired level
  4. Disable all Options
  5. Add Custom ruleset, pointing to vendor/yoast/yoastcs/phpmd.xml

You will see results inline, together with other inspections.

Running Laps performance profiler

  1. Install Laps plugin into WordPress installation, with Composer or built release download
  2. The Laps output in WordPress Toolbar will show performance breakdown of current page
  3. Laps has dedicated set of events for Yoast plugins (work in progress), events can be pull requested to Yoast_Events class or suggested on issue tracker

Running via test script (TODO outdated)

  1. Make sure you're on a (virtual) machine with PHP, MySQL, PEAR, PHPUnit and Git installed.
  2. Open a terminal and navigate to the plugin root folder, /wp-content/plugins/wordpress-seo
  3. Create a file with the contents of this gist and name it tests.sh
  4. Run bash tests.sh.

The script will then download the WordPress development suite, activate the plugin and run PHPUnit with the configuration included in the phpunit.xml file. It will also download and install PHP_CodeSniffer to check the code against the WordPress Code Standard.

Script environment variables

After running the tests.sh script it will ask you for the following environment variables to test against.

WP_MULTISITE

Possible values: 0, 1

WP_VERSION

Possible values: master, 3.9, 3.8 or any other valid develop.git.wordpress.org branch.