The definitive remote debug and unittest with PHPStorm guide: part 2
This post is part of the guide on how to setup your PHPStorm for remote debugging and unit testing. Click here for the beginning of this guide.
Autocompletion on PHPUnit files and assertions
One of the features of an IDE is the auto-completion and syntax detection of your code. Especially in complex libraries, having an auto-completion really can speed up your development. However, I see on occasion that PHPUnit autocompletion is missing. PHPUnit itself can be installed in many different ways: through composer, through PEAR or directly downloaded as a PHAR file. Unless you install PHPUnit through composer, PHPStorm won’t automatically pick up autocompletion directly:
A simple solution would be to just download the PHPUnit as a PHAR file. This is a very easy thing:
This will download the latest phpunit PHAR file. Place this file inside either a subdirectory of your project, or you COULD even have it stored on your local filesystem.
If you store the PHAR file inside your project, PHPStorm automatically picks this up and code completion is done out of the box. There is nothing else you need to do. However, if you store it on your local system, or maybe even install PHPUnit as a PEAR package, you must tell PHPStorm that you want to use the PHPUnit library.
Inside your project view, right click on the “External Libraries”, and select the “Configure PHP Include Paths”. We must add the path to our PHPUnit library, which in my case is located at /usr/lib/php/pear/PHPUnit, as I have installed the PHPUnit as a pear package on my local machine (even through I will never run this directly, it just for code completion!)
After applying this, phpstorm automatically find all the PHPUnit classes and methods:
Be careful with versions: if your vagrant machine has a PHPUnit installed (maybe even through PEAR), you might be using a different version with different methods. So even though PHPStorm is totally fine with a certain assertion method, your actual unit-test will fail, as that method might not be available as you are running the unit-tests through a different version of PHPUnit.
It’s easy to set up autocompletion for PHPUnit, but you have to be careful with versions. There are different ways of installing PHPUnit, and PHPStorm will automatically pick up autocompletion if you install through composer or store the PHAR file inside your project. Otherwise you just have to add the PHAR file manually through the “external libraries” inside your project view.
So, this was just a warmup to the next chapters. The important ones where we will discuss on how to setup XDebug and do some remote debugging. If you’re ready, then let’s continue…