Over a million developers have joined DZone.

Using Guard + PHPUnit for Great Good!

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Another day, another post about the tooling I’ve been using to make PHP development bearable. Today I’ll share guard-phpunit, which I discovered thanks to a tip by @ctshryock.

I’ve been using this as a replacement for watchr which I use to autorun tests whenever I make code changes. I’ve switched to guard for a number of reasons, chief amongst them being the awesome notification support. You can use growl, libnotify and rb-notifu to notify test pass/fail.

Here’s the Guardfile I’ve been using. This is tailored for Zend Framework 2 so that whenever I modify a php class under a module directory it will run the tests for that particular class. Rapid feedback for the win!

guard 'phpunit', :tests_path => 'test', :cli => '-c test/phpunit.xml' do
  # Watch tests files
  watch(%r{^.+Test\.php$})

  # Watch library files and run their tests
  watch(%r{^module/(.+)/src/.+/(.+)/(.+)\.php}) { |m| "test/#{m[1]}/#{m[2]}/#{m[3]}Test.php" }
end

 

 

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of James Carr, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}