Unish
Drush's command tests extend Drupal core's KernelTestBase. They instantiate a Symfony Console CommandTester object as is typical. See CircleCi.
Usage¶
git clone https://github.com/drush-ops/drush.gitcd drushcomposer install- Set
UNISH_DB_URLfor the kernel suite, for examplesqlite://localhost/:memory:?module=sqlite. - Run all test suites:
composer test
DDEV¶
Drush's own tests may be run within provided Docker containers via DDEV. It sets UNISH_DB_URL for you.
- Start containers:
ddev start - Run a test:
ddev exec composer kernel -- --filter testUserRole - See the DDEV's XDebug docs for help on enabling Xdebug.
Advanced usage¶
- Run only one test suite
composer unitcomposer kernel
- Run only tests matching a regex:
composer kernel -- --filter testUserRole - XML results:
composer kernel -- --log-junit results.xml
About the Test Suites¶
- Unit tests operate on functions that take values and return results without creating side effects. No database connection is required to run these tests, and no Drupal site is set up. They are configured in tests/phpunit.xml.dist.
- Kernel tests extend Drupal core's
KernelTestBaseand drive a command directly with Symfony'sCommandTester, the way Drupal core tests its own console commands. They run from tests/phpunit.kernel.xml.dist, whose bootstrap chains core's test bootstrap and derivesSIMPLETEST_DBfromUNISH_DB_URL. Each test gets a fresh, minimal Drupal with only the modules it lists. A class marked#[ShareEnvironment]builds that Drupal once, insetUpEnvironment(), and its test methods share the database; see the change record. QueueTest is a good model, both for Drush's own commands and for commands that ship in your module.