In this post to his site Matt Stauffer walks you through how he created a custom
@requires annotation to use in his PHPUnit testing. He needed a way to tell a test to only run if it wasn't being executed on the Travis CI service.
I was working on a project this weekend that required skipping certain tests in a particular environment (Travis CI). [...] I remembered that there was a @requires annotation in PHPUnit that works natively to allow you to skip a test under a certain version of PHP or with certain extensions disabled, so I set out to write my own custom @requires block.
He links to an article that helped him get most of the functionality in place but decided to restructure it a bit to make the override of the
checkRequirements method a bit clearer. He ends up using the Laravel
Collection functionality instead of a basic
foreach reducing it down to a closure that looks for an environment variable called
TRAVIS and automatically mark the test as skipped.