setting up PHPUnit for plugin development on Local by Flywheel

  1. Get local by flywheel
  2. Add a new local site
    • Custom install
    • PHP 7.3
    • nginx
    • Mysql 5.6
    • WP user: admin
    • WP password: admin
  3. Go to WP admin
  4. Install and activate the plugin you would like to test
  5. SSH into the site and run these commands:
    • apt-get update
    • apt-get install curl
    • apt-get install subversion
    • wget -O phpunit https://phar.phpunit.de/phpunit-7.phar
    • chmod +x phpunit
    • mv phpunit /usr/local/bin/phpunit
    • *** curl -s https://getcomposer.org/installer | php
    • *** mv composer.phar /usr/local/bin/composer
    • cd /app/public
    • *** composer require –dev phpunit/phpunit ^7
    • wp scaffold plugin-tests contact-form-7-conditional-fields-pro
    • cd wp-content/plugins/contact-form-7-conditional-fields-pro/
    • bin/install-wp-tests.sh wordpress_test root ‘root’ localhost latest
  6. Edit the file tests/bootsrap.php at line 25
    • function _manually_load_plugin() {
        require dirname( dirname( __FILE__ ) ) . '/contact-form-7-conditional-fields.php';
      }

       

  7. Edit the file phpunit.xml.dist:
    • <?xml version="1.0"?>
      <phpunit
      	bootstrap="tests/bootstrap.php"
      	backupGlobals="false"
      	colors="true"
      	convertErrorsToExceptions="true"
      	convertNoticesToExceptions="true"
      	convertWarningsToExceptions="true"
      	>
      	<testsuites>
      		<testsuite name="wptest">
      			<directory prefix="test-" suffix=".php">./tests/</directory>
      		</testsuite>
      	</testsuites>
      </phpunit>