Skip to content

Instantly share code, notes, and snippets.

@crstauf
Last active January 23, 2020 18:45
Show Gist options
  • Save crstauf/fdb551f9fb496a496b1fbec1c0400de0 to your computer and use it in GitHub Desktop.
Save crstauf/fdb551f9fb496a496b1fbec1c0400de0 to your computer and use it in GitHub Desktop.
Simple installation instructions for PHPUnit for WordPress plugin.

SSH Commands

Run the following commands in order:

  1. apt-get update
  2. apt-get install curl
  3. apt-get install subversion
  4. wget -O phpunit https://phar.phpunit.de/phpunit-7.phar
  5. chmod +x phpunit
  6. mv phpunit /usr/local/bin/phpunit
  7. curl -s https://getcomposer.org/installer | php
  8. mv composer.phar /usr/local/bin/composer
  9. cd /app/public
  10. composer require --dev phpunit/phpunit ^7
  11. wp scaffold plugin-test <plugin directory name>
  12. cd wp-content/plugins/<plugin directory name>
  13. bin/install-wp-tests.sh wordpress_test root 'root' localhost latest

Edit PHPUnit Config

Add name attribute on testsuite element in phpunit.xml.dist file:

<?xml version="1.0"?>
<phpunit
	bootstrap="tests/bootstrap.php"
	backupGlobals="false"
	colors="true"
	convertErrorsToExceptions="true"
	convertNoticesToExceptions="true"
	convertWarningsToExceptions="true"
>
	<testsuites>
		<testsuite name="<plugin directory name>">
			<directory prefix="test-" suffix=".php">./tests/</directory>
		</testsuite>
	</testsuites>
</phpunit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment