Project

General

Profile

Debugging CiviCRM cheatsheet » History » Version 13

Jon Goldberg, 10/11/2021 06:32 PM

1 7 Jon Goldberg
{{last_updated_at}} by {{last_updated_by}}
2
3 1 Jon Goldberg
# Debugging CiviCRM cheatsheet
4
5
### Command-line runs of PHPUnit:
6
7
From a buildkit civiroot, run a specific file's tests::
8
9 2 Jon Goldberg
```shell
10
CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php
11
```
12 1 Jon Goldberg
13
You can also limit to a single test by filtering on name:
14
15 2 Jon Goldberg
```shell
16
CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php --filter testShared
17
```
18 3 Jon Goldberg
19
### With XDebug
20 9 Jon Goldberg
21 10 Jon Goldberg
* You need to specify a full path to phpunit (because running `php <script>` won't check your path for the script, just `php`).
22
* You need to have XDebug otherwise configured for CLI.  Here's the contents of my `/etc/php/7.4/cli/conf.d/xdebug.ini`:
23 2 Jon Goldberg
24 1 Jon Goldberg
```
25 12 Jon Goldberg
xdebug.mode=debug,develop
26
xdebug.start_with_request=trigger
27 1 Jon Goldberg
xdebug.client_port=9000
28
xdebug.client_host = "127.0.0.1"
29 10 Jon Goldberg
xdebug.log=/var/log/xdebug.log
30 12 Jon Goldberg
#xdebug.mode=profile
31
#xdebug.output_dir = "/home/jon/temp/xdebug"
32 1 Jon Goldberg
```
33 5 Jon Goldberg
* You need to start a debugging session in VS Code with "Listen for XDebug".
34 1 Jon Goldberg
* Depending on your VS Code setup, you may need to listen on a different port (I can use the same port for FPM but not mod_php).
35 2 Jon Goldberg
36
Once you've got all that:
37 1 Jon Goldberg
```shell
38 12 Jon Goldberg
env CIVICRM_UF=UnitTests idekey=VSCODE php /home/jon/local/civicrm-buildkit/bin/phpunit7 /home/jon/local/civicrm-buildkit/build/dmaster/web/sites/all/modules/civicrm/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php --filter testSubmit
39 2 Jon Goldberg
```
40 6 Jon Goldberg
41 8 Jon Goldberg
### Command-line runs of standalone scripts
42 6 Jon Goldberg
```shell
43 13 Jon Goldberg
env XDEBUG_SESSION=VSCODE php myscript.php
44 6 Jon Goldberg
```