Mitchell McKenna - tagged with unit-testing http://mitchmckenna.com/feed en-us http://blogs.law.harvard.edu/tech/rss LifePress mitchellmckenna@gmail.com PHPStorm: Auto Run PHPUnit On File Save http://mitchmckenna.com/post/15957/phpstorm-auto-run-phpunit-on-file-save

You can setup PHPStorm to run PHPUnit every time you save a unit test. By doing this you get immediate feedback if your unit tests are passing as you write them. And by running PHPUnit only against the current file you’re editing it can run really fast.

To set this up we need to create a File Watcher:

Preferences > File Watchers

Click (+) sign and select custom to open the new file watcher dialog. Add the following settings:

  • Name: PHPUnit
  • File type: PHP
  • Scope: click the to create a new one called tests and use a pattern like file:tests/*.* if tests is the folder all your unit tests are located in and call it tests or something.
  • Program: $PhpExecutable$
  • Arguments: vendor/bin/phpunit --configuration phpunit.xml.dist $FileDirRelativeToProjectRoot$/$FileName$
  • Working directory: $ProjectFileDir$

]]>
Thu, 19 Nov 2015 15:11:00 -0500 http://mitchmckenna.com/post/15957/phpstorm-auto-run-phpunit-on-file-save/phpstorm-auto-run-phpunit-on-file-save
Setting Up PHPUnit in PHPStorm http://mitchmckenna.com/post/15237/setting-up-phpunit-in-phpstorm

This is more so just notes for how I got PHPUnit running in PHPStorm for my project. There's probably a more optimal way to set this up but this works for now.

Tell PHPStorm to Use Composer's Copy of PHPUnit And Set Default Config

Preferences > PHPUnit

Docs: Loading PHPUnit with Composer.

Edit PHPUnit Configuration to use your custom config file

Run > Edit Configurations

Click the plus (+) sign and select PHPUnit.

Docs: Run/Debug Configuration: PHPUnit.

You can now right click (or use the keyboard shortcut) on files or folders and run unit tests.

Note: It may prompt you to setup the PHP Interpreter, open up terminal and type which php to find out where the php version is that your using then paste that in as the interpreter location (related docs).

Results

PHPStorm now tells how much unit test coverage you have beside each file/folder in the navigation tree and a Coverage panel should slide in from the right.

Setup PHPUnit to Run in Vagrant

You might need to run your phpunit inside Vagrant for some reason, follow this guide to do so.

]]>
Wed, 04 Mar 2015 18:57:06 -0500 http://mitchmckenna.com/post/15237/setting-up-phpunit-in-phpstorm/setting-up-phpunit-in-phpstorm