How to debug PHPSpec via PHPStorm

Tutorial will show how to run tests and debug code by using PhpStorm breakpoints. To prepare guide PhpStorm v8.0.2 was used. Link to tutorial project is at the end of the article.

Steps how to run tests:

  1. Login to your vagrant machine: vagrant ssh
  2. Edit xdebug.ini file: sudo nano /etc/php5/mods-available/xdebug.ini
  3. At the end of file add:
    xdebug.remote_enable=on
    xdebug.remote_log="/var/log/xdebug.log"
    xdebug.remote_handler=dbgp
    xdebug.remote_port=9000
    xdebug.collect_params=1
    xdebug.remote_connect_back=Off
    xdebug.remote_host=192.168.56.1
    xdebug.default_enable = 1
    

    Line:

    xdebug.remote_host=192.168.56.1

    is a remote host address, mine is 192.168.56.101, last part of address change to 1

  4. In PhpStorm Click icon “Start listening for PHP debug connection”
    listen_icon
  5. Execute in command line tool export XDEBUG_CONFIG="idekey=PHPSTORM"
  6. Add breakpoint
  7. Run test:
    php bin/phpspec run

PhpStorm should catch the event and stop at breakpoint.

Working project could be found in github repository: https://github.com/MantasVaitkunas/debug_phpspec