Vanilla uses PHPUnit for testing it's backend code. Tests are written in PHP and can be easily run the from command line, or more commonly using PHPStorm.
Required Test Setup
The easiest way to get the full test harness setup is to use vanilla-docker.
After setting up vanilla docker, you will need to ensure you have a database named
vanilla_tests which will be used for tests requiring the database.
Next you will need to update your PHPUnit configuration file for your locale machine. It's recommended to copy the
phpunit.xml.dist in the root vanilla folder and rename it to
phpunit.xml. You can then make changes to the
Notably you will need need to change a few connection parameters.
You should set the following env variables.
<env name="TEST_DB_NAME" value="vanilla_test"/>
<env name="TEST_DB_USER" value="root" />
<env name="TEST_DB_PASSWORD" value="" />
<env name="TEST_DB_HOST" value="database" />
Some tests, may require additional services to be configured, such as tests for Memcached, Sphinx, and ElasticSearch.
Running the Tests from the Command Line
Tests can now be run from the command line.
# Run only certain groups of tests
./vendor/bin/phpunit --testsuite Library --textdox
./vendor/bin/phpunit --testsuite APIv2 --textdox
./vendor/bin/phpunit --testsuite APIv0 --textdox
# Run only tests in a particular directory.
./vendor/bin/phpunit --testdox applications/vanilla
Running Tests in PHPStorm
If you use PHPStorm, you can easily run you tests there, and get a nicer looking output and UI for running particular tests.