Debugging CiviCRM cheatsheet » History » Revision 12

Revision 11 (Jon Goldberg, 10/05/2021 05:37 PM) → Revision 12/47 (Jon Goldberg, 10/11/2021 06:32 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:: 

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

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

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


 ### With XDebug 

 * 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 (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`: 

 xdebug.mode=debug,develop xdebug.mode=off 
 xdebug.start_with_request=trigger xdebug.start_with_request=yes 
 xdebug.client_host = "" 
 #xdebug.output_dir = "/home/jon/temp/xdebug" 
 * You need to start a debugging session in VS Code with "Listen for XDebug". 
 * 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). 

 Once you've got all that: 
 env CIVICRM_UF=UnitTests idekey=VSCODE php -dxdebug.mode=debug,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 --filter testSubmit 


 ### Command-line runs of standalone scripts 
 env XDEBUG_SESSION=VSCODE php myscript.php