Setting up wordpress test environment

Step 1 : Getting your virtual environment up and running.

cd ~/Public
mkdir faisal
cd faisal
git clone https://github.com/scotch-io/scotch-box.git .
vagrant up
vagrant ssh

Step 2: Install SVN to get test wordpress codebase from wordpress.

sudo apt-get update
sudo apt-get install subversion

Step 3: Install phpUnit to run your unit tests

curl -O https://phar.phpunit.de/phpunit-4.8.phar
sudo chmod +x phpunit-4.8.phar
sudo mv phpunit-4.8.phar /usr/local/bin/phpunit
phpunit --version

StepĀ 4: Install WP-CLI to setupĀ the test environment

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp-cli
wp-cli --version

Step 5: Setting up the test plugin folder

curl -O https://wordpress.org/latest.tar.gz
tar xvzf latest.tar.gz .
cd wp-content/plugins/
mkdir demo
cd demo
touch demo.php
wp scaffold plugin-tests demo

Step 6: Setting up the test environment

cd ~/Public/faisal
bash bin/install-wp-tests.sh wordpress_test root root localhost latest

Step 6: Check if test is running or not.

cd ~/Public/faisal/wp-content/plugins/demo/
phpunit

You should now see something similar to this –

Advertisements