Ejemplo n.º 1
0
 /**
  * @test
  * @covers Cocur\Watchman\Watchman::addWatch()
  * @covers Cocur\Watchman\Watchman::runProcess()
  * @expectedException \RuntimeException
  */
 public function addWatchReturnsError()
 {
     $process = $this->getProcessMock();
     $process->shouldReceive('run')->once();
     $process->shouldReceive('stop')->once();
     $process->shouldReceive('getErrorOutput')->once();
     $process->shouldReceive('isSuccessful')->once()->andReturn(false);
     $factory = $this->getProcessFactoryMock();
     $factory->shouldReceive('create')->with('watchman watch /var/www/foo')->once()->andReturn($process);
     $this->watchman->setProcessFactory($factory);
     $this->watchman->addWatch('/var/www/foo');
 }
Ejemplo n.º 2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Watchman\Watchman;
$fooDir = __DIR__ . '/foo';
$barDir = __DIR__ . '/bar';
$invoke = __DIR__ . '/invoke.php';
if (!file_exists($fooDir)) {
    mkdir($fooDir);
}
if (!file_exists($barDir)) {
    mkdir($barDir);
}
$watchman = new Watchman();
$watch = $watchman->addWatch($fooDir);
$trigger = $watch->addTrigger('textfiles', '*.txt', "php {$invoke}");
echo "Added watch and trigger\n";
sleep(1);
file_put_contents($fooDir . '/1.txt', 'Hello ' . uniqid() . "\n");
sleep(1);
echo "Reading log file:\n";
echo file_get_contents($barDir . '/log.txt');
$trigger->delete();
$watch->delete();