To setup PHPUnit unit testing when developing Directus extensions, follow the steps given below:
Open the Directus extension's root directory.
Install PHPUnit via Composer:
In your extension folder, create a directory called ‘tests’ for storing your test files
Create a
phpunit.xml
) configuration file in your extension’s root directory. Example configuration:
In the ‘tests’ directory, create test classes for your extension. Here's an example
ExampleTest.php
:
In the terminal, run the following command from your extension's root directory: