Exemplo n.º 1
0
 public function testCreateNewFile()
 {
     //non-existing file
     $myFile2 = new LocalFile(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext');
     $this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     $this->assertTrue($myFile2->createNewFile());
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     //already existing file (overwrite = false)
     try {
         $myFile2->createNewFile();
         $this->fail();
     } catch (EyeIOException $e) {
         //normal situation
     }
     //already existing file (overwrite = true)
     $content = '## My Content ##';
     file_put_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext', $content);
     $this->assertEquals($content, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     try {
         $myFile2->createNewFile(true);
     } catch (EyeIOException $e) {
         $this->fail();
     }
     $this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     $this->assertEquals('', file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext'));
     unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile2.ext');
 }
Exemplo n.º 2
0
 /**
  * @param bool $overwrite Set to TRUE to try overwriting the file if it already exists
  * @return void
  * @throws EyeIOException
  */
 public function createNewFile($overwrite = false)
 {
     $this->getParentFile()->checkWritePermission();
     try {
         return parent::createNewFile($overwrite);
     } catch (EyeIOException $e) {
         throw new EyeIOException('Unable to create file at ' . $this->getAbsolutePath());
     }
 }