Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm 8 remote PHPUnit mapping not working

I have a vagrant VM out of my project (my projects are set-up vagrant-vm/sites/myproject)

My tests are in myproject/application/tests and I have set-up the following in phpstorm:

  1. I have a remote PHP interpreter (5.5.15-1~dotdeb.1) on my VM, set as default for my project.
  2. I have By Remote Interpreter PHPUnit configuration set up as Path to phpunit.phar and the path of it inside my VM /home/vagrant/phpunit.phar
  3. I have an SFTP deployment configuration set as default for the project, with mapping set up.

But when I run my PHPUnit run config (PHPUnit not PHPUnit on Server), I get the following log:

vagrant://C:/Users/Hugo/Documents/Projects/vagrant-swappy/usr/bin/php /home/vagrant/.phpstorm_helpers/phpunit.php --no-configuration C:\Users\Hugo\Documents\Projects\vagrant-swappy\sites\swappy\application\tests
Testing started at 11:19 ...
PHPUnit 4.1.4 by Sebastian Bergmann.

bash: line 0: cd: C:/Users/Hugo/Documents/Projects/vagrant-swappy/sites/swappy/application/tests: No such file or directory
Cannot open file "C:UsersHugoDocumentsProjectsvagrant-swappysitesswappyapplicationtests.php".


Process finished with exit code 1

EDIT: Some screenshots:

  • PHPUnit settings: http://i.imgur.com/KAvWYBP.png
  • Remote interpreter: http://i.imgur.com/0C3w1wC.png
  • Deployment SFTP: http://i.imgur.com/QSS2WI7.png
like image 761
Korri Avatar asked Aug 06 '14 15:08

Korri


2 Answers

I know this is old but I had the same issue and wanted to leave this to help others.

My setup:

  • PHPStorm(8) on my Host.
  • CentOS as my Guest (vagrant)
  • Tested on Ubuntu and Mac Host

I started first by setting the global settings. This way, all new projects will inherit the default settings. Currently setup projects will need to apply the global settings for this to work.

If you have not setup your default interpreter already, you should do this now. Go to Language & Frameworks->PHP. Make sure the interpreter is setup to use your vagrant interpreter. To do this, click on the ... and select remote, select vagrant and point to your box location. Hit OK and you should see it connect to you box. If all is good, hit OK again to get back to the select box for your default interpreter and click on Apply.

I also recommend going to Tools->Vagrant and setup your default vagrant. This is how my setup is but I don't believe this has any affect on getting PHPUnit to work on Vagrant, just a preference. Just noting this here in case this actually had any affect.

First, let's get PHPStorms autocomplete working.

Download the latest phpunit.phar and save locally on the host. I recommend having a directory strictly for IDE resources and put the phar file in that directory. Go to Language & Frameworks->PHP and add the IDE resources directory to your include path. This will enable autocomplete for your code.

Next, open Default Settings, not project settings (although existing projects will need this done too), and go to Language & Frameworks->PHP->PHPUnit. Under Local, select Path to phpunit.phar and update this to point to your newly downloaded phpunit.phar file.

Next, we need to let PHPUnit be aware of Vagrant.

In Language & Frameworks->PHP->PHPUnit add a new PHPUnit. Select By Remote Interpreter and select your newly added Vagrant Interpreter. Choose your selected method, for me, I tried to use include path but it was giving me errors (didn't care to fix it). I wound up using Use custom autoloader and set my path to /usr/local/bin/phpunit since I installed it manually and this was my path. Basically, all you want to do is let PHPStorm know where PHPUnit is installed if you are experiencing issues with this.

Do not check anything for Test Runner as this is global settings. If you are in a project, then you would need to check Default configuration file and point to your projects phpunit.xml file. This should load your VM and the path should be the location in your VM. If it's not your VM, you selected the wrong interpreter. You will need to do this for any project you want to do unit testing on (unless you created a default phpunit.xml config for all projects and set this in the global settings. Keep in mind, existing project may need to be updated to use the global config.)

Now the environment is setup (assuming you used the above for global and project settings) and the last thing to do is to configure the tests.

On the top-right side of the IDE, next to the debugger icons, is a drop down. Click on it and select Edit Configurations

Add a new PHPUnit test. I named mine, Run Tests and select Defined in configuration file (this is important otherwise it will try to use your local path instead of your Vagrant path.) Apply and Save.

Now your tests should work.

If you have any issues, or are a bit confused, I only set the default (global) settings so all new projects inherit the settings. Basically, your project settings just need to match what's above.

I was having a lot of issues getting this to work and found PHPStorms documentation to be less than helpful. Google brought me here but setting a Deployment is not the proper method to do this.

Hope this helps.

like image 65
Jeremy Avatar answered Oct 22 '22 21:10

Jeremy


This feature is actually working, but PHPStorm isn't mapping your paths. For your remote setup on the "Interpreters" try selecting "Deployment configuration" and selecting your SFTP deployment configuration. Also make sure your SFTP mappings will let PHPStorm map all your file paths, and not just your web-accessible paths. The "Web path on server ..." setting under your deployment is sometimes meaningless.

It seems that there is currently no support for vagrant-specific path mapping, although I suppose that will come. However, it ends up being a bit of a red herring.

like image 33
Ryan Avatar answered Oct 22 '22 21:10

Ryan