示例#1
0
 /**
  * testPermissions method
  *
  * @return void
  */
 public function testPermissions()
 {
     $this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.');
     $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'permissions' . DIRECTORY_SEPARATOR;
     $old = umask();
     umask(02);
     $filename = $dir . 'permission_' . uniqid();
     $expecting = decoct(0664 & ~umask());
     $file = new File($filename, true);
     $fileInfo = new FileInfo($file);
     $result = $fileInfo->permissions();
     $this->assertEquals($expecting, $result);
     $file->delete();
     umask(022);
     $filename = $dir . 'permission_' . uniqid();
     $expecting = decoct(0644 & ~umask());
     $file = new File($filename, true);
     $fileInfo = new FileInfo($file);
     $result = $fileInfo->permissions();
     $this->assertEquals($expecting, $result);
     $file->delete();
     umask(0422);
     $filename = $dir . 'permission_' . uniqid();
     $expecting = decoct(0244 & ~umask());
     $file = new File($filename, true);
     $fileInfo = new FileInfo($file);
     $result = $fileInfo->permissions();
     $this->assertEquals($expecting, $result);
     $file->delete();
     umask(0444);
     $filename = $dir . 'permission_' . uniqid();
     $expecting = decoct(0222 & ~umask());
     $file = new File($filename, true);
     $fileInfo = new FileInfo($file);
     $result = $fileInfo->permissions();
     $this->assertEquals($expecting, $result);
     $file->delete();
     umask($old);
 }
示例#2
0
 /**
  * testAppend method
  *
  * @return void
  */
 public function testAppend()
 {
     if (!($tmpFile = $this->_getTmpFile())) {
         return false;
     }
     if (file_exists($tmpFile)) {
         unlink($tmpFile);
     }
     $TmpFile = new File($tmpFile);
     $this->assertFalse(file_exists($tmpFile));
     $fragments = ['CoreTyson\'s', ' test suite', ' was here ...'];
     $data = null;
     $size = 0;
     foreach ($fragments as $fragment) {
         $r = $TmpFile->append($fragment);
         $this->assertTrue($r);
         $this->assertTrue(file_exists($tmpFile));
         $data = $data . $fragment;
         $this->assertEquals($data, file_get_contents($tmpFile));
         $TmpFileInfo = new FileInfo($TmpFile);
         $newSize = $TmpFileInfo->size();
         $this->assertTrue($newSize > $size);
         $size = $newSize;
         $TmpFile->close();
     }
     $TmpFile->append('');
     $this->assertEquals($data, file_get_contents($tmpFile));
     $TmpFile->close();
 }