Installing the PHPUnit test suite
All of the preceding types of tests (with the exception of NightwatchJS tests) are executed from one test harness, PHPUnit. We can add any number of tests to our custom modules or custom themes and run them using PHPUnit – all we have to do is install it and configure it to point at our test files.
Getting ready
The first thing to do before proceeding is to install all the test dependencies so that you can actually run tests in Drupal. Drupal has a specific Composer package that brings in PHPUnit and the required dependencies for it.
To install, follow these steps:
Open up a Terminal (command line) at the root of your project.
Run the following Composer command:
composer require --dev drupal/core-dev:^10
The drupal/core-dev
package will bring in PHPUnit and various dependencies to your project that are needed for writing and running tests in Drupal.
The --dev flag
Note that when installing, we are using the --dev
flag...