-
-
Notifications
You must be signed in to change notification settings - Fork 648
Xdebug PHPUnit Tests from within VM - CLI and/or PHPStorm #716
Comments
This is a question where I can't help too terribly much, since I'm not using PHPStorm (though I've considered starting many times now...). Hopefully someone else can chime in and help? |
ok, I feel a little silly - seems that xdebug was not installed for some reason. I updated my
Then did a
And sure enough, I got nothing back... Switching the following in my config.yml got xdebug back up and running
to
I don't think the PHPStorm PHPUnit debug configuration is going to work though because it still doesn't seem to find any classes when I click, "Choose Test Class". But oddly, PHPStorm does find the Test Class for a test at the project root that subclasses TestBase.php https://github.com/acquia/blt/blob/8.x/template/tests/phpunit/src/TestBase.php In fact, all of the tests here seem to work correctly from within PHPStorm without any issue. This feels like an AutoLoad issue to me but I'm just guessing. I'll try again from the command line now that I have xdebug working again. Update: Created a note in the documentation about this. |
@geerlingguy Any ideas why my config settings for xdebug wouldn't be getting applied?
Here's what I see when I print out my php settings:
Note that the idekey is not set nor is the remote_enable, or remote_connect_back even though I have them set in my config.yml |
If you are trying to run unit tests from PHPStorm or the command line, I think there was a longstanding issue recently fixed in core that allows this to work now, though I could be mistaken. I had an issue in the past where my unit tests worked from the UI page in Drupal, but running them from the command line or unit runner tool in PHPStorm did nothing. One thing that really helps is to make sure that the PHP Interpreter settings are pointing at the package inside of the VM via the Vagrant integration in PHPStorm, and not using the host machine PHP. https://www.jetbrains.com/help/phpstorm/2016.1/configuring-remote-php-interpreters.html See: "Configuring a PHP Interpreter in a Vagrant Instance" This helps me run Behat tests, among many other things. |
@kevinquillen Thanks for the comment. I'm actually not having any issues running my custom module phpUnit tests from the command line or via the simpletest module. It's just that I'm having no luck getting PHPStorm execute, and more importantly, to pause using xdebug. I'm not a huge fan of printing my instance variables to the screen in order to debug something. I've put together a much more detailed question detailing the issue here: |
@justinlevi - Have you gotten anywhere with this? I'm not sure if there's anything I can do in Drupal VM in particular to help further the effort, as it looks like it may be more related to how PHPStorm is working with the debugging, and not debugging itself not working correctly in PHP installed in the VM... |
Negative. I ended up giving up on it as I was able to debug my phpunit tests from the drupal testing interface. This is not ideal and I would love to find a solution at some point. I'll close this out. |
Sounds good. Testing is still not as easy as it should be :( |
@justinlevi Am I correct in understanding that your goal is to get a PHP script started via command line inside the VM ( If so, one way I've done this is to set You may need to also set |
@kentr - I forgot about this thread. Thanks for the idea. That does seem like it would work. I have since switched to using this plugin which has made this process much easier |
To debug phpunit in phpstorm from drupalvm, prepend following settings before the phpunit command (or any other php-based command):
Example (run from docroot/core directory of D8 installation): Run unit test without debugging: Run unit test with debugging enabled: This assumes that you already have installed and enabled xdebug globally in drupalvm config ( This should not only work for phpunit, but also for any other php-based script. Note however that the best practice is to not have xdebug plugin for CLI loaded and enabled globally in php.ini, but to load xdebug plugin only if you want to debug your script. Otherwise you will get performance penalty on all php-based CLI scripts (including composer, drush etc.), even if you don't intend to debug. For this, xdebug.so must be present on vm, but by default neither enabled nor loaded (then you can use the similar CLI trick with prepending PHP settings that load and enable xdebug.so on demand). If I will have some more time, I will try to set this up on drupalvm somehow. |
To get Drush working, I do the following: First, I enabled xdebug enabled on drupalvm, and the configured PHPSTORM with a 'PHP Remote Debug' server, pointing to a hostname identified below (ie: testsite.dev) Then add the following to .bashrc: export PHP_IDE_CONFIG="serverName=testsite.dev"
export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=10.0.2.2"
export PHP_OPTIONS="-dxdebug.remote_autostart=On -didekey=PHPSTORM -dremote_host=testsite.dev -dprofiler_enable=1" With this patch, this should bring up the debugger when running drush. YMMV depending on how your PHPSTORM project is setup, but most basic setups should work. |
Wouldnt it be better that ansible generated those lines to the vagrant users bashrc and based them on the config.yaml settings. That way you don't have to export them first on your host. Im refering to this this #1171 |
Iv also added these files https://gist.github.com/FinBoWa/9e54697233284bdf0302a67ccc5f4f81 to help on quickly toggling xdebug on our projects |
There are now docs on how to do this from your host machine as well http://docs.drupalvm.com/en/latest/extras/xdebug/#xdebug-over-sshdrush (will be available in the next release). |
I realize this is a bit off topic but thought I'd throw out the question here anyway. I'm writing some PHPUnit tests for a D8 custom module and doing the development work on the VM. XDebug is setup and working fine for breakpoints if I load the site through my browser. However, I'm running into an exception for one of my tests and I'd like to debug within PHPStorm and I don't want to run my tests by using the testing module. I'm not even sure if that would work in the first place...
I've tried to create quite a few different PHPStorm debug configurations both using the default PHPUnit configuration and the php script configuration with no luck. I've also tried to run my tests from the command line, which works fine, but I can't get XDebug to trip.
Here's the command line I'm trying to run
Here's a shell script I created to make my life a bit easier
source: http://vlikin.blogspot.com/2013/11/debuggingtracing-drupal-8-tests.html
I've also tried setting up a debug configuration in PHPStorm with the following settings, per slide 22 of the talk below:
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
http://www.slideshare.net/FranciscoSeva/xdebug-and-drupal
Here's the thing that's totally throwing me off though. This site is a Bolt derivative, so all dependencies are managed with composer, and the tests within
/var/www/dvm/tests/phpunit
all run as expected in PHPStorm. I was thinking this could be an Autoloader issue but I tried to run google_analytics tests from within PHPStorm and I'm getting the same errors.What is the the workflow for debugging(xdebug) PHPUnit tests for a custom module from within PHPStorm? If I can get this all setup and working I will definitely do a blog post on this one...
The text was updated successfully, but these errors were encountered: