Esempio n. 1
0
 /**
  * @test
  * @covers Cocur\Watchman\Watchman::since()
  * @covers Cocur\Watchman\Watchman::runProcess()
  */
 public function sinceWithWatchObjectIsSuccessful()
 {
     $process = $this->getProcessMock();
     $process->shouldReceive('run')->once();
     $process->shouldReceive('stop')->once();
     $process->shouldReceive('isSuccessful')->once()->andReturn(true);
     $process->shouldReceive('getOutput')->once()->andReturn($this->getFixtures('since-success.json'));
     $factory = $this->getProcessFactoryMock();
     $factory->shouldReceive('create')->with('watchman since /var/www/foo c:1398642060:75924:1:1 *.scss')->once()->andReturn($process);
     $watch = m::mock('Cocur\\Watchman\\Watch');
     $watch->shouldReceive('getRoot')->once()->andReturn('/var/www/foo');
     $this->watchman->setProcessFactory($factory);
     $this->assertEquals('sass/main.scss', $this->watchman->since($watch, 'c:1398642060:75924:1:1', '*.scss')[0]['name']);
 }
<?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();
Esempio n. 3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Cocur\Watchman\Watchman;
$watchman = new Watchman();
$watchman->watchLogByLevel('debug', function ($message) {
    echo "{$message}\n";
});