예제 #1
0
 /**
  * {@inheritDoc}
  */
 protected function onDispose(bool $disposing, bool &$isDisposed)
 {
     parent::onDispose($disposing, $isDisposed);
     if (!$disposing || !$isDisposed) {
         return;
     }
     if ($this->_deleteOnDispose) {
         $isDisposed = \unlink($this->file());
     }
 }
예제 #2
0
 public function test1()
 {
     $file = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt');
     $this->assertNotFalse($file);
     $s = FileStream::openRead($file);
     try {
         $this->assertTrue($s->canRead());
         $this->assertTrue($s->canSeek());
         $this->assertFalse($s->canWrite());
         $arr = [];
         $this->assertSame(ord('a'), $s->readByte());
         while (null !== ($data = $s->read(5))) {
             $arr[] = (string) $data;
         }
         $this->assertEquals(4, count($arr));
         $this->assertSame('01234', $arr[0]);
         $this->assertSame('56789', $arr[1]);
         $this->assertSame('ABCDE', $arr[2]);
         $this->assertSame('F', $arr[3]);
     } finally {
         $s->dispose();
     }
 }
예제 #3
0
 public function testPrependStream()
 {
     $this->checkTransformMethod(function (IString $str) {
         $fs = FileStream::openRead(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt');
         try {
             return $str->prependStream($fs);
         } finally {
             $fs->dispose();
         }
     }, 'xyzABC', 'ABC');
     $this->checkTransformMethod(function (IString $str) {
         $fs = FileStream::openRead(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt');
         try {
             $fs->readByte();
             return $str->prependStream($fs);
         } finally {
             $fs->dispose();
         }
     }, 'yzABC', 'ABC');
     $this->checkTransformMethod(function (IString $str) {
         $fs = FileStream::openRead(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt');
         try {
             $fs->read(3);
             return $str->prependStream($fs);
         } finally {
             $fs->dispose();
         }
     }, 'ABC', 'ABC');
 }