Code for the workshop "An Introduction to Unit Testing (for WordPress)" at WordCamp Europe 2018.
To be able to do the exercises in this workshop, you need to meet some requirements.
In order to run the PHP tests, you need to have installed the following:
- PHP 5.6 or higher (available via command line)
- Composer
In order to run the JavaScript tests, you need to have installed the following:
Here are the steps to install and set up your environment for the workshop:
- Clone (or download) this repository to your computer.
- In your terminal, go to the root directory of this repository.
- Install the dependencies:
- For PHP, run
composer install
. - For JavaScript, run
yarn
(ornpm i
).
- For PHP, run
You can test if everything is working by attempting to run one of the exercises as described in the next section.
Each exercise has its own test suite/file. To run a specific exercise, perform the according command from the root directory of the repository, as explained below.
For each PHP exercise, there is a dedicated test suite, named exercise1
to exercise3
.
The generic command to run a specific test suite is as follows:
./vendor/bin/phpunit --testsuite exerciseX
Replace the "X" in exerciseX
with the exercise number.
So, for example, running the test suite for exercise 1 would be this:
./vendor/bin/phpunit --testsuite exercise1
For each JavaScript exercise, there are one or more dedicated test files, named exercise1/SOMETHING.test.js
etc.
The generic command to run a specific test suite is as follows:
./node_modules/.bin/jest exerciseX
Replace the "X" in exerciseX
with the exercise number.
So, for example, running the test suite for exercise 1 would be this:
./node_modules/.bin/jest exercise1
Throughout the workshop, you might want to refer to the official documentation of the tools you are using.
Thorsten, Carl, and Giuseppe