Project

General

Profile

Debugging CiviCRM cheatsheet » History » Revision 10

Revision 9 (Jon Goldberg, 07/22/2021 08:34 PM) → Revision 10/47 (Jon Goldberg, 10/05/2021 05:30 PM)

{{last_updated_at}} by {{last_updated_by}} 

 # Debugging CiviCRM cheatsheet 

 ### Command-line runs of PHPUnit: 

 From a buildkit civiroot, run a specific file's tests:: 

 ```shell 
 CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php 
 ``` 

 You can also limit to a single test by filtering on name: 

 ```shell 
 CIVICRM_UF=UnitTests phpunit5 tests/phpunit/CRM/Core/BAO/AddressTest.php --filter testShared 
 ``` 

 ### With XDebug 

 **FIXME: This needs updating for XDebug 3, this is basically all incorrect now** 

 * 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); 
 * You need to specify a full path to phpunit phpunit5 (because running `php <script>` won't check your path for the script, just `php`). 
 * You need to have XDebug otherwise configured for CLI.    Here's the contents of my `/etc/php/7.4/cli/conf.d/xdebug.ini`: `/etc/php/7.3/cli/conf.d/xdebug.ini`: 

 ``` 
 xdebug.mode=off xdebug.remote_enable=1 
 xdebug.start_with_request=yes xdebug.remote_autostart=1 
 xdebug.client_port=9000 xdebug.remote_handler=dbgp 
 xdebug.client_host = "127.0.0.1" xdebug.remote_mode=req 
 xdebug.log=/var/log/xdebug.log xdebug.remote_host=127.0.0.1 
 xdebug.remote_port=9000 
 ``` 
 * You need to start a debugging session in VS Code with "Listen for XDebug". 

 Once you've got all that: 
 ```shell 
 env CIVICRM_UF=UnitTests idekey=VSCODE php -dxdebug.mode=develop /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 -dzend_extension=/usr/lib/php/20180731/xdebug.so /home/jon/local/civicrm-buildkit/bin/phpunit5 tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php --filter testSubmit '^.*::testIgnoreLocationTypeId( .*)?$ 
 ``` 

 ### Command-line runs of standalone scripts 
 ```shell 
 env XDEBUG_SESSION=VSCODE php -dzend_extension=xdebug.so myscript.php 
 ```