-
Notifications
You must be signed in to change notification settings - Fork 5
Debugging PHP tests
Mart Sõmermaa edited this page Mar 12, 2024
·
3 revisions
To debug PHP tests in Ubuntu (assuming PHP 8.2 is the default) with Visual Studio Code:
-
Install Xdebug:
sudo apt install php8.2-dev sudo pecl install xdebug
-
Enable Xdebug:
php --ini # verify the INI file location sudo su echo 'zend_extension=/usr/lib/php/20220829/xdebug.so' >> /etc/php/8.2/cli/conf.d/99-xdebug.ini
-
Verify that it is enabled:
$ php --version PHP 8.2.16 (cli) (built: Mar 7 2024 08:55:56) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.16, Copyright (c) Zend Technologies with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
-
Activate debugging by adding the following lines to
/etc/php/8.2/cli/conf.d/99-xdebug.ini
:xdebug.mode = debug xdebug.start_with_request = yes
-
Open VS Code and install the PHP Debug extension.
-
Activate debugging according to instructions on the extension site.
- In your project, go to the debugger and hit the little gear icon and choose PHP. A new launch configuration will be created for you...
-
Test debugging.
- Add a breakpoint in VS Code.
- Press the Listen for Xdebug button in Run and debug mode, the debugging session will become active.
- Run tests on command-line with
composer test
. - The breakpoint will be hit in VS Code, you can examine the variables and use the debugging toolbar: