Using PhpStorm for CiviCRM Development¶
PHPStorm is a commercial IDE which is popular among CiviCRM developers.
General project setup¶
- Use the root directory of your CMS as your project root (otherwise in-app debugging won't work)
- You can speed up PhpStorm's indexing process by taking the following steps to ignore most files:
- Settings > Directories
- Mark all directories as "Excluded"
- Drill down to find the "civicrm" folder and mark it as "Sources"
Code style setup¶
Create the 'CiviCRM' code styling preference:
- Open you current project's properties: File > Settings
- Create the CiviCRM code styling preference: Code Style > Manage > Save as, then indicate 'CiviCRM'
- In the 'Code style' sub-menu, select 'PHP', then 'Set from ...' at the far right, Predefined Style > Drupal (this sets options across all tabs of the dialog)
- Click 'Apply' at the bottom of the screen
That's it. You can now use this code style on all future CiviCRM-related projects. If you are only developing for CiviCRM, you can also copy this style to the 'Default' style.
You need to configure XDebug on the webserver, phpstorm on the development machine and a debugger helper in the browser.
To configure XDebug and PHPStorm see: https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html
For browser helpers see: https://confluence.jetbrains.com/display/PhpStorm/Browser+Debugging+Extensions
Running automated tests from within PHPStorm¶
PHPStorm provides convenient tools for running and debugging unit tests in-app.
These instructions assume you already have a working instance of CiviCRM running locally with buildkit.
- On the CLI from a directory inside your build, run the command
civibuild phpunit-info. This outputs configuration settings you will need to paste into PHPStorm.
- From the
Run > Edit Configurationsmenu edit the default PHPUnit configuration for your project.
- Check "Use alternative configuration file" and choose the one output by the
- Set the custom working directory as specified by the
- Expand "Environment variables" and add the variables shown in the
For more detailed instructions (with screenshots!) see this StackExchange answer.
Adding external libraries¶
It can be frustrating when writing tests the PHPStorm complains about missing classes or undefined methods. This happens because PHPUnit is not included in the CiviCRM codebase.
To remedy this you can add an external content root. You'll need to clone the PHPUnit library locally. Then from that directory check out the latest supported version of PHPUnit (4.x right now).
After that you just add the directory to your project include paths by following the instructions on the Jetbrains site.
Alternatively: always use buildkit to generate you CiviCRM development environment; it ships with many tools - including PHPUnit 4