Project

General

Profile

Debugging CiviCRM cheatsheet » History » Version 5

Jon Goldberg, 07/03/2020 09:16 PM

1 1 Jon Goldberg
# Debugging CiviCRM cheatsheet
2
3
### Command-line runs of PHPUnit:
4
5
From a buildkit civiroot, run a specific file's tests::
6
7 2 Jon Goldberg
```shell
8
CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php
9
```
10 1 Jon Goldberg
11
You can also limit to a single test by filtering on name:
12
13 2 Jon Goldberg
```shell
14
CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php --filter testShared
15
```
16 3 Jon Goldberg
17
### With XDebug
18 2 Jon Goldberg
* You need to define an additional php.ini setting at runtime (otherwise XDebug will always be on for CLI, leading to a big loss in performance);
19
* You need to specify a full path to phpunit5 (because running `php <script>` won't check your path for the script, just `php`).
20
* You need to have XDebug otherwise configured for CLI.  Here's the contents of my `/etc/php/7.3/cli/conf.d/xdebug.ini`:
21 4 Jon Goldberg
22 2 Jon Goldberg
```
23
xdebug.remote_enable=1
24
xdebug.remote_autostart=1
25
xdebug.remote_handler=dbgp
26
xdebug.remote_mode=req
27
xdebug.remote_host=127.0.0.1
28
xdebug.remote_port=9000
29 1 Jon Goldberg
```
30 5 Jon Goldberg
* You need to start a debugging session in VS Code with "Listen for XDebug".
31 2 Jon Goldberg
32
Once you've got all that:
33
```shell
34 5 Jon Goldberg
env CIVICRM_UF=UnitTests idekey=VSCODE php -dzend_extension=/usr/lib/php/20180731/xdebug.so /home/jon/local/civicrm-buildkit/bin/phpunit5 tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php --filter '^.*::testIgnoreLocationTypeId( .*)?$
35 2 Jon Goldberg
```