Advertisement
Hanafi112

unit test

Apr 30th, 2023
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | Source Code | 0 0
  1. class FileUploadTest extends \PHPUnit\Framework\TestCase
  2. {
  3.     public function testUpload()
  4.     {
  5.         // membuat dummy file
  6.         $filename = 'dummy.txt';
  7.         $handle = fopen($filename, 'w');
  8.         fwrite($handle, 'Ini adalah konten dari file dummy');
  9.         fclose($handle);
  10.        
  11.         // melakukan upload file menggunakan fungsi yang ingin di-test
  12.         $uploader = new FileUploader();
  13.         $result = $uploader->upload($filename);
  14.        
  15.         // melakukan assertion untuk memastikan file berhasil di-upload
  16.         $this->assertTrue($result);
  17.        
  18.         // menghapus dummy file setelah testing selesai
  19.         unlink($filename);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement