コード例 #1
0
ファイル: FileTest.php プロジェクト: naucon/file
 /**
  * @depends     testExist
  * @return      void
  */
 public function testCopy()
 {
     // create file
     $filePath = __DIR__ . '/tmp/example_copy.txt';
     if (!is_file($filePath)) {
         fclose(fopen($filePath, 'x'));
     }
     // create target dir
     $newPath = __DIR__ . '/tmp/target';
     if (!is_dir($newPath)) {
         mkdir($newPath, 0777);
     }
     // remove copied file
     $filePathNew = $newPath . '/example_copy.txt';
     if (is_file($filePathNew)) {
         unlink($filePathNew);
     }
     $fileObject = new File($filePath);
     $this->assertTrue($fileObject->isFile());
     $this->assertTrue($fileObject->isWritable());
     $this->assertTrue($fileObject->copy($newPath));
     $this->assertEquals($filePathNew, $fileObject->getPathname());
     $this->assertTrue($fileObject->isFile());
     // create dir
     $filePath = __DIR__ . '/tmp/ExampleCopy';
     if (!is_dir($filePath)) {
         mkdir($filePath, 0777);
     }
     // remove copied file
     $filePathNew = $newPath . '/ExampleCopy';
     if (is_dir($filePathNew)) {
         rmdir($filePathNew);
     }
     $fileObject = new File($filePath);
     $this->assertTrue($fileObject->isDir());
     $this->assertTrue($fileObject->isWritable());
     $this->assertTrue($fileObject->copy($newPath));
     $this->assertEquals($filePathNew, $fileObject->getPathname());
     $this->assertTrue($fileObject->isDir());
 }