For the PHP developers among us who test their code using PHPUnit, Sublime has an awesome plugin to support PHPUnit known as sublime-phpunit, written by Stuart Herbert and located at http://github.com/stuartherbert/sublime-phpunit.
If you are a PHP developer and do not know what PHPUnit is, you should learn that PHPUnit is "the standard" for unit testing in PHP projects. It combines a framework that lets us easily write and run tests with the facility to analyze the results.
We can learn more about PHPUnit at https://github.com/sebastianbergmann/phpunit/ or check the full manual at http://phpunit.de/manual/current/en/index.html.
Before using this plugin, we must have PHPUnit installed and functional in our project and know how to use it, a topic which is not covered here. We'll then need to download and install the PHPUnit plugin using Package Control. Let's open up the command palette by pressing Ctrl + Shift + P in Windows or Linux and Command + Shift + P in OS X. Then choose Install Package and install PHPUnit package. After installing it, we can right-click on our code to see the new the PHPUnit option that has been added to our context menu, as shown in the following screenshot:
The options in PHPUnit are disabled because we are not currently inside a PHP project. To use the PHPUnit plugin in our project, we'll need a phpunit.xml
or phpunit.xml.dist
file. These files contain all the PHPUnit configuration options.
PHPUnit will always favor phpunit.xml
over phpunit.xml.dist
if both exist. After your project is properly configured, right-clicking inside a source file should show the following:
As we can see in the preceding screenshot, we have three available options in the PHPUnit menu:
phpunit.xml
file.We can also find all the available PHPUnit commands inside the command palette by pressing Ctrl + Shift + P on Windows or Linux and Command + Shift + P on OS X, and type phpunit
, as shown in the following screenshot:
In the preceding screenshot, we can see all available commands that the PHPUnit plugin has to offer.
The PHPUnit plugin also includes some very helpful snippets to use while writing our unit tests:
These snippets can be used like any regular snippet, by typing their names and pressing the Tab key.