Run PHPUnit test on vagrant VM using PHPStorm
To run unit tests on virtual machine using PHPStorm 7.1 IDE is not that hard. I’ll show it by creating new project called “vagrant-test”. First you should start VM using vagrant. How to do this is explained in this post: https://phpforus.com/run-first-application-with-vagrant-in-very-fast-way/
Now our VM is running, so let’s do these steps:
- Create new project using PHPStorm.
- Let’s start our VM:
cd _vagrant/ vagrant up
- Create unit test using PHPStorm IDE: right mouse click on project directory “New->PHPUnit->PHPUnit Test”. Let’s call it “helloTest”
- Click “OK”.
My test will look like this:<?php class helloTest extends PHPUnit_Framework_TestCase { public function testHelloWorld() { $this->assertEquals( 2, 2 ); } }
- Now we need to download PHPUnit lib, with PHPStorm we can do that easily from IDE. Just go to File->Settings->PHP->PHPUnit, than check radio button “Path to phpunit.phar” and click download link.
- Click “OK”. Now in project directory you should see phpunit.phar file.
- Now we need to configure PHPStorm with server information. Go to Tools->Deployment->Configuration. Click “+”, then select type- SFTP and enter all needed information which depends on your VM, check picture below what I entered:
- Now click “Mappings”:
and “OK”.[easy_ad_inject_1]
- Now go to “Run->Edit Configurations->Defaults->PHPUnit on Server”. Let’s select newly created server:
- “OK”.
- If we did not forgot anything we will run our test on VM using PHPStorm successfully. Right click on unit test file and “Run->helloTest on vagrant…”. We will see something like this: