Prerequisites
Before adding a PHPUnit test to your Code Studio pipeline, you must:
Understand how to implement PHPUnit tests.
Include
drupal/core-dev
andphpunit/phpunit
in thecomposer.json
file of your project.Place the
phpunit.xml.dist
file in the root directory of your project.Ensure that a custom module exists in your codebase.
Adding a PHPUnit test to your custom module
In your custom module, create a directory for
tests/src/Functional/
.For example,
docroot/modules/custom/my_module/tests/src/Functional
.Add a PHPUnit test file.
For example,
ExampleTest.php
.Add your PHPUnit test cases to the test file.
Updating the PHPUnit configuration file
In the phpunit.xml.dist
file, ensure that the path to your custom modules directory exists under a test suite.
For example, if your module exists in the docroot/modules/custom/
directory, ensure that the phpunit.xml.dist
file
contains the following:
<?xml version="1.0"?>
<!-- phpunit.xml.dist -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Custom modules">
<directory>docroot/modules/custom/</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
Adding project variables
The following variables must be set in your project:
ACQUIA_TASKS_SETUP_DRUPAL
must be set totrue
. For more information, see Adding environment variables.If
ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT
exists, it must be set totrue
.If
ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY
exists, it must be set toinstall
.If
ACQUIA_TASKS_PHPUNIT
exists, it must be set totrue
.If
ACQUIA_JOBS_TEST_DRUPAL
exists, it must be set totrue
.