Wouldn't it be great if your PHPUnit tests would be automatically rerun whenever you change some code? This package can do exactly that.
With the package installed you can do this:
phpunit-watcher watch
Here's how it looks like:
This will run the tests and rerun them whenever a file in the app
, src
or tests
directory is modified.
Want to pass some arguments to PHPUnit? No problem, just tack them on:
phpunit-watcher watch --filter=it_can_run_a_single_test
You're free to use this package (it's MIT-licensed), but if you use it often we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
You can install this package globally like this
composer global require spatie/phpunit-watcher
After that phpunit-watcher watch
can be run in any directory on your system.
Alternatively you can install the package locally as a dev dependency in your project
composer require spatie/phpunit-watcher --dev
Locally installed you can run it with vendor/bin/phpunit-watcher watch
All the examples assume you've installed the package globally. If you opted for the local installation prepend vendor/bin/
everywhere where phpunit-watcher
is mentioned.
You can start the watcher with:
phpunit-watcher watch
This will run the tests and rerun them whenever a file in the src
or tests
directory is modified.
Want to pass some arguments to PHPUnit? No problem, just tack them on:
phpunit-watcher watch --filter=it_can_run_a_single_test
Certain aspects of the behaviour of the tool can be modified. All options can be set in a .phpunit-watcher.yml
in your project directory.
If a such a config file does not exist in the project directory, the tool will check if the file exists in any of the parent directories of the project directory.
Here's some example content. Read on for a more detailed explanation of all the options.
watch:
directories:
- src
- tests
fileMask: '*.php'
notifications:
passingTests: false
failingTests: false
phpunit:
arguments: '--stop-on-failure'
You can customize the directories being watched by creating a file named .phpunit-watcher.yml
in your project directory. Here's some example content:
watch:
directories:
- src
- tests
fileMask: '*.php'
By default the tool will display desktop notifications whenever the tests pass or fail. If you want to disable certain desktop notifications update .phpunit-watcher.yml
by adding a notifications
key.
notifications:
passingTests: false
failingTests: false
If you want to use pass the same arguments to PHPUnit everytime to watcher starts, you can specificy those in the .phpunit-watcher.yml
config file. Here's an example:
phpunit:
arguments: '--stop-on-failure'
When starting the tool with some arguments (eg phpunit-watcher watch --filter=my_favourite_test
) those arguments will get used instead of the ones specified in the config file.
Please see CHANGELOG for more information what has changed recently.
composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
We started creating this package after reading this excellent article by Christoper Pitt
Interactive commands were inspired by Jest.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
The MIT License (MIT). Please see License File for more information.