public function testIsLocked() { $path = 'application/data/filesystem/test.txt'; $fs = FileSystem::getInstance(); $file = new File($path); $lockFile = $file->getLockFile(); if ($lockFile->exists()) { $lockFile->delete(); } $this->assertFalse($fs->isLocked($file)); $lockFile->write('test'); $this->assertTrue($fs->isLocked($file)); }
/** * @dataProvider providerGetLockFile */ public function testGetLockFile($expected, $value) { $file = new File($value); $lockFile = $file->getLockFile($file); $this->assertEquals($expected, $lockFile->getPath(), $value); }
/** * Wait until the provided file is unlocked * @param File $file The locked file to wait for * @param integer $waitTime Time in microseconds to wait between the lock checks * @return null */ public function waitForUnlock(File $file, $waitTime = 10000) { $lockFile = $file->getLockFile(); $isFileLocked = true; do { if ($this->exists($lockFile)) { usleep($waitTime); continue; } $isFileLocked = false; } while ($isFileLocked); }