---
title: "PHP tools"
date: "2024-11-06T09:54:06+00:00"
summary: "Discover essential PHP tools for Drupal development in Cloud IDE. Learn to use Composer, Xdebug, PHP Code Sniffer, Drush, and PHPUnit effectively. Streamline your workflow and improve code quality."
image:
type: "page"
url: "/acquia-cloud-platform/add-ons/cloud-ide/php-tools"
id: "0fce15a8-971b-42c2-8a60-b34bbe707dae"
---

Cloud IDE supports the following PHP tools:

*   [Composer](#ide-composer)
*   [Xdebug](#ide-xdebug)
*   [PHP Code Sniffer](#ide-php-code-sniffer)
*   [Drush](#ide-drush)
*   [PHPUnit](#ide-phpunit)

Composer
--------

Cloud IDE supports Composer 2 to manage PHP dependencies. Composer 2 can be invoked by running the `composer` command. To view all Composer commands, visit the [Composer documentation](https://getcomposer.org/doc/03-cli.md/).

Xdebug
------

Cloud IDE provides preconfigured [Xdebug](https://xdebug.org/) to help you debug Drupal applications.

### Enabling or disabling Xdebug

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Run the `acli ide:xdebug-toggle` command to enable or disable Xdebug:
    
        ide:~/project $ acli ide:xdebug-toggle
        xDebug PHP extension enabled.
        ide:~/project $ acli ide:xdebug-toggle
        xDebug PHP extension disabled.
    

### Editing the default settings of Xdebug

1.  In your Cloud IDE, locate the `/home/ide/configs/php/xdebug.ini` file.
2.  Edit the file to modify the required settings:
    
        ; Acquia Hosting XDebug defaults
        ; This file configures the default settings for xdebug.
        [xdebug]
        zend_extension=xdebug.so
        xdebug.mode=develop
        xdebug.client_host=127.0.0.1
        xdebug.client_port=9001
        xdebug.max_nesting_level=3000
        xdebug.log = /tmp/fcso_debug.log
    
    Important
    
    Do not edit the `zend_extension=xdebug.so` line.
    
3.  Restart FastCGI Process Manager (PHP-FPM) to implement the changes:
    
        acli ide:service-restart php
    
    For more information about using Xdebug with Cloud IDE, visit [Using Xdebug](https://www.youtube.com/watch?v=bNZ6u1dtJzE).
    

### Debugging Drush

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Add the `DRUSH_ALLOW_XDEBUG=1` environment variable before your Drush command and then run the command to override the default behavior of the [Drush launcher](https://github.com/drush-ops/drush-launcher#xdebug-compatibility).
    
    For example, to debug the `pm:list` Drush command, add a breakpoint to the `pmList` method in `./vendor/drush/drush/src/Drupal/Commands/pm/PmCommands.php`, and run the following command:
    
        DRUSH_ALLOW_XDEBUG=1 drush pm:list
    

PHP Code Sniffer
----------------

Cloud IDE supports PHP Code Sniffer to help you write quality code. Cloud IDE enforces Drupal best practices with the pre-installed `Drupal` and `DrupalPractice` code sniffs.

    ide:~/project (master) $ phpcs -i
    The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, AcquiaDrupalStrict, AcquiaDrupalTransitional, AcquiaEdge, AcquiaPHP, Drupal, DrupalPractice, PHPCompatibility, VariableAnalysis and SlevomatCodingStandard.

To run PHP Code Sniffer against any supported Drupal file:

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Invoke the `phpcs` command and pass the path to the file or the directory:
    
        ide:~/project (master) $ phpcs docroot/core/core.api.php
        FILE: /home/ide/project/docroot/core/core.api.php
        ------------------------------------------------------------------------------
        FOUND 13 ERRORS AND 1 WARNING AFFECTING 14 LINES
        ------------------------------------------------------------------------------
            8 | ERROR   | [ ] Missing short description in doc comment
          459 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
         1956 | ERROR   | [ ] Type hint "array" missing for $data_types
         1973 | ERROR   | [ ] Type hint "array" missing for $queues
         1992 | ERROR   | [ ] Missing parameter type
         2039 | ERROR   | [x] Doc comment short description must end with a full stop
         2045 | ERROR   | [ ] Missing parameter type
         2047 | ERROR   | [ ] Missing parameter type
         2068 | ERROR   | [ ] Missing parameter type
         2122 | ERROR   | [ ] Type hint "array" missing for $info
         2129 | ERROR   | [ ] Missing parameter type
         2158 | ERROR   | [ ] Type hint "array" missing for $definitions
         2232 | ERROR   | [ ] Type hint "array" missing for $sync_steps
         2254 | ERROR   | [ ] Missing parameter type
        ------------------------------------------------------------------------------
        PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
        ------------------------------------------------------------------------------
    

Drush
-----

Cloud IDE supports Drush 8 for Drupal 7 applications. For the [current Drupal version](/service-offerings/guide/software-life-cycle#supported-drupal-version), the best practice is to add Drush to your `composer.json` file:

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Run the following command:
    
        composer require drush/drush
    

PHPUnit
-------

Cloud IDE supports the following Drupal tests:

*   Unit tests
*   Kernel tests
*   Functional tests
*   Functional JavaScript tests with ChromeDriver

### Reviewing environment variables

Cloud IDE requires multiple environment variables to run Drupal tests, and configures ChromeDriver to establish a connection with the database.

    ide:~/project (master) $ env | grep -E '(TEST|DTT|MINK)'
    MINK_DRIVER_ARGS_WEBDRIVER=["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless","--disable-dev-shm-usage"]}}, "http://127.0.0.1:4444"]
    DTT_MINK_DRIVER_ARGS=["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless","--disable-dev-shm-usage"]}}, "http://127.0.0.1:4444"]
    DTT_BASE_URL=http://127.0.0.1
    SIMPLETEST_BASE_URL=http://127.0.0.1
    SIMPLETEST_DB=mysql://drupal:drupal@127.0.0.1/drupal

### Installing and running PHPUnit

To run Drupal tests, you need PHPUnit. To install PHPUnit, pull the Drupal development dependencies:

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Run the following command:
    
        composer require --dev drupal/core-dev:*
    

The following is an example of a test executed within the `docroot` directory:

    ide:~/project/docroot (master *) $ ../vendor/bin/phpunit -c core --debug --verbose --group=ban
    PHPUnit 8.5.15 by Sebastian Bergmann and contributors.
    Runtime:       PHP 7.4.14
    Configuration: /home/ide/project/docroot/core/phpunit.xml.dist
    Testing
    Test 'Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp' started
    Test 'Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp' ended
    Test 'Drupal\Tests\ban\Unit\BanMiddlewareTest::testUnbannedIp' started
    Test 'Drupal\Tests\ban\Unit\BanMiddlewareTest::testUnbannedIp' ended
    Test 'Drupal\Tests\ban\Kernel\Plugin\migrate\source\d7\BlockedIpsTest::testSource with data set #0 (array(array(array(1, '127.0.0.1'))), array(array('127.0.0.1')))' started
    Test 'Drupal\Tests\ban\Kernel\Plugin\migrate\source\d7\BlockedIpsTest::testSource with data set #0 (array(array(array(1, '127.0.0.1'))), array(array('127.0.0.1')))' ended
    Test 'Drupal\Tests\ban\Kernel\Migrate\d7\MigrateBlockedIpsTest::testBlockedIps' started
    Test 'Drupal\Tests\ban\Kernel\Migrate\d7\MigrateBlockedIpsTest::testBlockedIps' ended
    Test 'Drupal\Tests\ban\Functional\IpAddressBlockingTest::testIPAddressValidation' started
    Test 'Drupal\Tests\ban\Functional\IpAddressBlockingTest::testIPAddressValidation' ended
    Time: 17.94 seconds, Memory: 853.00 MB
    OK (5 tests, 41 assertions)

### Running functional JavaScript tests

Run ChromeDriver before you execute Drupal’s functional JavaScript tests.

To launch ChromeDriver:

1.  In the Cloud IDE menu bar, click **Terminal** > **New Terminal**.
2.  Run the following command:
    
        ide:~/project/docroot (master *) $ chromedriver --port=4444&
        [1] 4838
        Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 4444
        Only local connections are allowed.
        Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
        ChromeDriver was started successfully.
    
3.  To allow the process to continue running in the background, pass the `&` character at the end of the command.
4.  Run functional JavaScript tests after ChromeDriver is launched:
    
        ide:~/project/docroot (master *) $ ../vendor/bin/phpunit -c core --debug --verbose core/modules/user/tests/src/FunctionalJavascript
        PHPUnit 8.5.15 by Sebastian Bergmann and contributors.
        Runtime:       PHP 7.4.14
        Configuration: /home/ide/project/docroot/core/phpunit.xml.dist
        Testing core/modules/user/tests/src/FunctionalJavascript
        Test 'Drupal\Tests\user\FunctionalJavascript\RegistrationWithUserFieldsTest::testRegistrationWithUserFields' started
        Test 'Drupal\Tests\user\FunctionalJavascript\RegistrationWithUserFieldsTest::testRegistrationWithUserFields' ended
        Test 'Drupal\Tests\user\FunctionalJavascript\UserPasswordResetTest::testUserPasswordResetWithAdditionalAjaxForm' started
        Test 'Drupal\Tests\user\FunctionalJavascript\UserPasswordResetTest::testUserPasswordResetWithAdditionalAjaxForm' ended
        Time: 28.88 seconds, Memory: 8.00 MB
        OK (2 tests, 10 assertions)
    
5.  After running functional JavaScript tests, terminate the ChromeDriver process to free up CPU and memory in your IDE.
    
        ide:~/project/docroot (master *) $ pkill chromedriver
        [1]+  Terminated              chromedriver --port=4444
    

For more information about Drupal tests, visit [Running PHPUnit tests](https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/running-phpunit-tests).