Watch for changes in your Peridot tests and re run them when a change occurs.
We recommend installing this plugin to your project via composer:
$ composer require --dev peridot-php/peridot-watcher-plugin:~1.3
You can register the plugin via your peridot.php file.
<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Watcher\WatcherPlugin;
return function(EventEmitterInterface $emitter) {
$watcher = new WatcherPlugin($emitter);
};
Registering the plugin will make a --watch
option available to the Peridot application:
vendor/bin/peridot specs/ --watch
By default, the watcher plugin will look for a "file changed" event, but you can configure the plugin to listen for the following events:
- WatcherInterface::CREATE_EVENT
- WatcherInterface::MODIFY_EVENT
- WatcherInterface::DELETE_EVENT
- WatcherInterface::ALL_EVENT
<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Watcher\WatcherPlugin;
use Peridot\Plugin\Watcher\WatcherInterface;
return function(EventEmitterInterface $emitter) {
$watcher = new WatcherPlugin($emitter);
$watcher->setEvents([WatcherInterface::CREATE_EVENT, WatcherInterface::MODIFY_EVENT]);
};
By default, the watcher plugin just monitors the test path. If you want to track additional paths, you can do so in your peridot.php file:
<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Watcher\WatcherPlugin;
return function(EventEmitterInterface $emitter) {
$watcher = new WatcherPlugin($emitter);
$watcher->track(__DIR__ . '/src');
};
The watcher will look for changes in files ending in .php by default. If you want to track additional file types, you can add criteria as regular expressions in your peridot.php file:
<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Watcher\WatcherPlugin;
return function(EventEmitterInterface $emitter) {
$watcher = new WatcherPlugin($emitter);
$watcher->track(__DIR__ . '/src');
$watcher->addFileCriteria('/\.js$/');
};
Using the above, you can re run your tests when the source file changes. Since the Peridot watcher re runs your tests in a sub-process, it will actually detect new changes in your source.
Feel free to play around with the example spec using the watch option:
$ vendor/bin/peridot -c example/peridot.php example/modifyme.spec.php --watch
$ vendor/bin/peridot specs/
The watcher plugin will leverage the Inotify extension if it is available, otherwise it will use a recursive directory strategy to watch for changes.
Some IDEs might choke on ANSI sequences being returned from the watcher process. PHPStorm does not render colors
from sub process output, but most terminals will. If using the terminal from your IDE is a must, you may want to run your
tests using the --no-colors
option.