Code Studio

Adding a PHPUnit test to the Code Studio pipeline


Before adding a PHPUnit test to your Code Studio pipeline, you must:

  1. Understand how to implement PHPUnit tests.

  2. Include drupal/core-dev and phpunit/phpunit in the composer.json file of your project.

  3. Place the phpunit.xml.dist file in the root directory of your project.

  4. Ensure that a custom module exists in your codebase.

Adding a PHPUnit test to your custom module

  1. In your custom module, create a directory for tests/src/Functional/.

    For example, docroot/modules/custom/my_module/tests/src/Functional.

  2. Add a PHPUnit test file.

    For example, ExampleTest.php.

  3. 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="" xsi:noNamespaceSchemaLocation="">
   <coverage processUncoveredFiles="true">
         <directory suffix=".php">src</directory>
         <clover outputFile="build/logs/clover.xml"/>
      <testsuite name="Custom modules">

Adding project variables

  • The following variables must be set in your project:

    • ACQUIA_TASKS_SETUP_DRUPAL must be set to true. For more information, see Adding environment variables.

    • If ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT exists, it must be set to true.

    • If ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY exists, it must be set to install.

    • If ACQUIA_TASKS_PHPUNIT exists, it must be set to true.

    • If ACQUIA_JOBS_TEST_DRUPAL exists, it must be set to true.