A solution for testing Drupal 7 using PhpUnit.
This is a complete testing solution for using PhpUnit with Drupal 7 websites. It provides Unit, Kernel, and Client abstract test classes to use in writing your tests, a single test runner, testing for modules and themes, support for JsonSchema validation, as well as a set of guidelines and processes for better testing of Drupal 7 modules and websites. All of this using a single test runner that can be divided by test suite or filtered by test class using normal PhpUnit options.
Finally, manual functional tests are supported as well.
Visit https://aklump.github.io/drupal-test for full documentation.
After installation (see below), follow instructions in the documentation (docs/index.html) to write and run tests.
If you find this project useful... please consider making a donation.
From inside the directory above the web root run this one-liner:
[ ! -d tests ] && git clone https://github.com/aklump/drupal-test.git tests && (cd tests && ./bin/install.sh) || echo "Installation error, nothing installed."
The following files are considered core and should never be modified.
drupal_test.yml drupal_test_bootstrap.php LICENSE README.md
Additionally, do not add files to the following folders, which are replaced on every update. It is safe to add classes to src so long as you avoid src/DrupalTest.
Do not modify any of the files in bin, which are provided by this module. You may add your own files to bin, if you wish.
From inside the tests directory, run:
This will copy over the core files from the latest repository, but leave the non-core files alone, namely phpunit.xml and composer.json, which you most-likely will have modified.
See documentation for more information about configuration.
- Open tests/composer.json and add module and theme composer.json filepaths.
- From tests run
composer update --lock.
- Open tests/phpunit.xml and add any JSON schema directories.
$ cd tests $ phpunit -c phpunit.xml
$ cd tests $ phpunit -c phpunit.xml --testsuite Unit
$ cd tests $ phpunit -c phpunit.xml --testsuite Kernel
$ cd tests $ phpunit -c phpunit.xml --testsuite Client
Refer to the documentation for more info.