Debugging CiviCRM cheatsheet » History » Version 7
Jon Goldberg, 11/09/2020 07:38 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 | 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); |
21 | * You need to specify a full path to phpunit5 (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.3/cli/conf.d/xdebug.ini`: |
||
23 | 4 | Jon Goldberg | |
24 | 2 | Jon Goldberg | ``` |
25 | xdebug.remote_enable=1 |
||
26 | xdebug.remote_autostart=1 |
||
27 | xdebug.remote_handler=dbgp |
||
28 | xdebug.remote_mode=req |
||
29 | xdebug.remote_host=127.0.0.1 |
||
30 | xdebug.remote_port=9000 |
||
31 | 1 | Jon Goldberg | ``` |
32 | 5 | Jon Goldberg | * You need to start a debugging session in VS Code with "Listen for XDebug". |
33 | 2 | Jon Goldberg | |
34 | Once you've got all that: |
||
35 | ```shell |
||
36 | 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( .*)?$ |
37 | 2 | Jon Goldberg | ``` |
38 | 6 | Jon Goldberg | |
39 | ### Command-line runs of standalong scripts |
||
40 | ```shell |
||
41 | env idekey=VSCODE php -dzend_extension=/usr/lib/php/20180731/xdebug.so myscript.php |
||
42 | ``` |