function let(Listener $listener) { MFS::mkdir(MFS::$tmpDir); $listener->hasPath(Argument::any())->willReturn(true); $listener->getPatterns()->willReturn(array()); $listener->getIgnores()->willReturn(array()); }
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); }
/** * @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); } }
/** * @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); } }
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); }