Some time ago I wrote an analogous reminder: How to run WordPress tests in VVV using PHPStorm 8. Today I can do it again. And I really mean can instead of a simpler and also possible must. In fact, only some minutes ago I was able to solve this issue.
In my mentioned article, I explained how to do everything for the ´wordpress-develop´ site. It is what allows you to develop the WordPress core, for example for fixing a bug. And with the help of VVV / Vagrant / VirtualBox, setting up the environment is almost a painless task.
At some point I decided it was time to start developing the new version of my very old Enzymes plugin. I thought that it would make a lot of sense to take advantage of the ´wordpress-default´ site which VVV provides too, so I checked out my plugin code from wordpress.org, and, for some days, I could think and write my new code in a PHPStorm project, as I use to.
When I needed to debug an intermittently failing test, I recalled that I had written a reminder about that, and happily read it and applied all those steps again… to no avail. Oops.
Of course there had to be some difference. The first one I could think of was that before I had used the ´phpunit.xml.dist´ configuration file that came packaged with VVV, while now I was trying to use the ´phpunit.xml´ generated by the ´wp scaffold plugin-tests´ command. However it didn’t seem the right issue here.
What absolutely I could not understand was why I could run my PHPUnit tests smoothly from the command line but not from PHPStorm, not even following my own fabulous how-to instructions that had worked so well before. It drove me crazy, and more so because I couldn’t solve it.
From time to time I got back to having a need for debugging my tests, and tried to configure PHPStorm again, but never succeeded.
Today I also tried an alternative I found on the PHPStorm issue tracking site. WI-25653: Path mapping not considered when running PHPUnit tests with remote interpreter… I really wanted the solution outlined in the comment to be the one, but I couldn’t make that work either.
I was very sad. It had to be the solution, because that was almost exactly the problem I had:
Of course the problem I had was that PHPStorm was trying to access a path in my hosting environment (OSX) thinking it was a path in the hosted environment (Ubuntu). In fact my ´phpunit.xml´ file not only was very real, but I had previously selected it with PHPStorm itself !!
So I deleted that field, unchecked the Use alternative configuration file, and clicked on that last icon on the right… Just because.
It opened the PHPUnit dialog, which I knew very well already.
Well, better to look at the remote configuration.
Then, all of a sudden, I noticed something that I saw many many times before.
I checked the Default configuration file and clicked on the button on the right. It opened this:
Tah-Dah!! That’s it: Remote browsing!!
So I selected my ´phpunit.xml´ file.
Lastly, the dialog for the PHPUnit / Remote configuration looked like this:
After the click on OK I had this:
Simple to solve issue this one. Just refresh the Run/Debug Configurations dialog by checking and unchecking the Use alternative configuration file. And we’re ready to go:
Wow ! Almost there. Notice how the configuration file is working perfectly fine now.
Hm… I saw this piece of path ´/tmp/wordpress-tests-lib´ in the ´bootstrap.php´ file… right.
What is the value of ´WP_TESTS_DIR´ when I execute PHPUnit from the CLI?
If I put that in my Run/Debug Configurations dialog?
Alleluia, alleluia, alleluia.
(The backtrace is part of my stuff.)
Actually, no! It’s not working YET !!!
I can run and debug, I mean, I can click on the run and on the debug buttons and PHPStorm completes without any difference with respect to what I have when I run PHPUnit from the CLI. When I get reds in the CLI, I also get reds in PHPStorm, and when I get greens in the CLI, I also get greens in PHPStorm.
BUT there is no way to make PHPStorm see my breakpoints !! It simply ignores them.
To be fair, PHPStorm tells me something. There is an x on the breakpoint icon. Hovering, it displays this message: “File path is not mapped to any file path on server. Edit path mappings to fix the problem.” Very cryptic, or very wrong. I remember that I set my path mappings before.
Clicking on Validate remote environment I got this:
Well, not exactly, because this is what it’s supposed to look like when it’s fixed 🙂 In my case, the Deployment server was empty and its selection list was empty too, so there was no other option than to click on the top-right button.
Same as above, this is what the Deployment / Connection panel is supposed to look like when it’s fixed.
- The Type must be ´SFTP´.
- The SFTP Host and Root path must be respectively ´local.wordpress.dev´ and ´/vagrant/www/wordpress-default´ which are the host name and the root directory for the ´wordpress-default´ site.
- Upload/download project files / Test SFTP connection… and Browse files on server / Open must work fine.
- I decided to set the Name equal to the SFTP Host (easier for me).
- User name and Password are both ´vagrant´, as per VVV setup.
- Autodetect does not work. For me it got ´/home/vagrant´ but that didn’t work (it didn’t make much sense either…).
- Last, but not least: check Save password.
And now the infamous Deployment / Mappings panel.
Here you could have a couple of entries: if so, remove one and make your panel look like the one above.
- Local path must be the path corresponding to the Root path on the Connection panel, thus ´~/dev/wp/vvv/www/wordpress-default´.
- Deployment path… must be the path corresponding to Local path, but considering the Root path on the Connection panel, thus ´/´.
- Web path… well… I think this one should be the same as the previous one, according to how all other fields are configured.
Lastly, after clicking the Validate Remote Environment / Validate button, I got:
Is that right? No idea, but at least it doesn’t say it’s wrong either :D. Funny, no OK button here… use Cancel.
Will it work now? NO!
There is yet another step, which (luckily?) I could find in this forum thread: PHPStorm 8 / Vagrant / Xdebug.
The crucial last point is… to tell PHPStorm to mind that whatever we were doing in the last couple of hours we really meant it. And how do we do it? Like this.
Open again the dialog for the PHPUnit / Remote configuration (I showed it above) and click on the top-right button, next to the Interpreter selection box.
Once again, this is how the Interpreters dialog is supposed to look like when it’s fixed. In my dialog I had selected Remote / Vagrant, but of course, the correct option is… Remote / Deployment configuration. And make sure Test connection really works.
Now… NOW IT DOES WORK !!
After using it a few hours, here is a better configuration, to have path mappings also for debugging into the WordPress code that my testing bash file downloads and installs: ´bash bin/install-wp-tests.sh test-db root root localhost latest´.
First, Deployment / Connection.
And then, Deployment / Mappings.
It works fine because my ´wordpress-default´ site is actually the latest stable version, so anything in ´/tmp/wordpress´ and in ´~/dev/wp/vvv/www/wordpress-default´ corresponds to each other one to one.