コード例 #1
0
ファイル: BasicAdapterSpec.php プロジェクト: phpguard/listen
 function let(Listener $listener)
 {
     MFS::mkdir(MFS::$tmpDir);
     $listener->hasPath(Argument::any())->willReturn(true);
     $listener->getPatterns()->willReturn(array());
     $listener->getIgnores()->willReturn(array());
 }
コード例 #2
0
 function it_should_listen_to_file_system_delete_event(Listener $listener)
 {
     $newFile = MFS::$tmpDir . '/delete.txt';
     touch($newFile);
     $listener->getPaths()->shouldBeCalled()->willReturn(array(MFS::$tmpDir));
     $listener->hasPath(Argument::any())->shouldBeCalled()->willReturn(true);
     $this->beConstructedWith(null);
     $this->initialize($listener);
     unlink($newFile);
     $this->evaluate();
     $this->getChangeSet()->shouldHaveCount(1);
 }
コード例 #3
0
ファイル: Tracker.php プロジェクト: phpguard/listen
 /**
  * @param $path
  * @throws \PhpGuard\Listen\Exception\InvalidArgumentException
  * @internal param \Symfony\Component\Finder\SplFileInfo $spl
  */
 public function checkPath($path)
 {
     $id = PathUtil::createPathID($path);
     if (!$this->has($id)) {
         if (!is_readable($path)) {
             return;
         }
         if (!$path instanceof SplFileInfo) {
             $absPath = realpath($path);
             foreach ($this->listener->getPaths() as $baseDir) {
                 $baseDir = realpath($baseDir);
                 $baseDirLen = strlen($baseDir);
                 if ($baseDir === substr($absPath, 0, $baseDirLen)) {
                     $path = PathUtil::createSplFileInfo($baseDir, $absPath);
                     break;
                 }
             }
         }
         if (!$path instanceof SplFileInfo) {
             throw new InvalidArgumentException(sprintf('Path "%s" can not registered', $path));
         }
         if (!$this->listener->hasPath($path)) {
             return;
         }
         // path is new
         if ($path->isFile()) {
             $resource = new FileResource($path);
         } else {
             $resource = new DirectoryResource($path);
         }
         $tracked = $this->createTrackedObject($resource);
         $this->add($tracked);
         $this->addChangeSet($tracked, FilesystemEvent::CREATE);
         return;
     }
     $tracked = $this->get($id);
     $origin = $tracked->getResource();
     if ($tracked->getChecksum() !== $origin->getChecksum() && $origin->isExists()) {
         // path is modified
         $this->addChangeSet($tracked, FilesystemEvent::MODIFY);
         $tracked->setChecksum($origin->getChecksum());
         unset($this->unchecked[$id]);
         return;
     }
     if (!$origin->isExists()) {
         // path is deleted
         $this->addChangeSet($tracked, FilesystemEvent::DELETE);
         $this->remove($tracked);
     }
 }
コード例 #4
0
ファイル: ListenerTest.php プロジェクト: phpguard/listen
 /**
  * @param $pattern
  * @param $path
  * @param bool $expected
  * @dataProvider getShouldOnlyMatchPattern
  */
 public function testShouldOnlyMatchPattern($pattern, $path, $expected = true)
 {
     $dirname = dirname($path);
     $this->mkdir($dirname);
     touch($path);
     $listener = new Listener(self::$tmpDir);
     //$spl = new SplFileInfo($file,$subPath,$subPathName);
     $listener->patterns($pattern);
     $retVal = $listener->hasPath($path);
     if ($expected) {
         $this->assertTrue($retVal);
     } else {
         $this->assertFalse($retVal);
     }
 }
コード例 #5
0
ファイル: TrackerSpec.php プロジェクト: phpguard/listen
 function its_checkPath_should_track_on_filesystem_create_event(AdapterInterface $adapter, Listener $listener)
 {
     $newFile = MFS::$tmpDir . '/new.txt';
     $listener->hasPath($newFile)->shouldBeCalled()->willReturn(true);
     $adapter->watch(Argument::any())->shouldBeCalled();
     $this->beConstructedWith($adapter);
     $this->initialize($listener);
     touch($newFile);
     $this->checkPath($newFile);
     $this->getChangeSet()->shouldHaveCount(1);
 }