Example #1
0
 /**
  * @todo fix mixed return types!
  * @return boolean|string
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function tail()
 {
     if (version_compare(phpversion(), '5.5.11', '<')) {
         trigger_error(sprintf('%s is not supported on PHP %s < 5.5.11.', __METHOD__, phpversion()), E_USER_ERROR);
         return false;
     }
     $file = new File($this->getPathname(), 'r');
     if ($file->fseek(0, SEEK_END) == -1) {
         return false;
     }
     $end = $file->ftell();
     if ($end === false) {
         return false;
     }
     if ($this->tailSeek === -1) {
         $this->tailSeek = $end;
     }
     if ($end < 0) {
         return '';
     }
     if ($end <= $this->tailSeek) {
         return '';
     }
     if ($file->fseek($this->tailSeek) == -1) {
         return false;
     }
     $content = $file->fread(4096);
     if ($content === false) {
         return false;
     }
     $this->tailSeek = $file->ftell();
     unset($file);
     return $content;
 }
Example #2
0
    /** @covers \phpDocumentor\Fileset\File::fread() */
    public function testFreadWithValidSplFileInfoObjectOfTestTextFile()
    {
        $file = new File(new \SplFileInfo($this->getNameOfDataDir() . 'fileWithText.txt'));
        $expected = <<<END
one line of text...
another line of text.
END;
        $actual = $file->fread();
        $this->assertEquals($expected, $actual);
    }