Reputation: 29
Can anybody help me. How to write file upload phpunit testcase? I done it for insert, unique data insertion, delete etc functionality. Following are my code but its not working properly
class FileuploadTest extends PHPUnit_Framework_TestCase
{
public $testFile = array(
'name'=>'2012-04-20 21.13.42.jpg',
'tmp_name'=>'C:\wamp\tmp\php8D20.tmp',
'type'=>'image/jpeg',
'size'=>1472190,
'error'=>0
);
public function testFileupload()
{
$testUpload = new Fileupload;
$testUpload->image = new CUploadedFile($this->testFile['name'],$this->testFile['tmp_name'],$this->testFile['type'],$this->testFile['size'],$this->testFile['error']);
$this->assertFalse($testUpload->validate());
$errors= $testUpload->errors;
$this->assertEmpty($errors);
}
}
Upvotes: 0
Views: 2983
Reputation: 17478
According to your comments, that's what testing is, the $testUpload->validate()
is returning true, and you are trying to assert
if it is false, obviously the test will fail.
If $this->assertFalse($testUpload->validate());
is failing, it means that $testUpload
is correctly initialized, and hence validation returns true.
To move on to the next assertion in your test you need to use
$this->assertTrue($testUpload->validate());
You need to read more about unit testing. There are lots of articles on the web, that a simple search will return.
Upvotes: 1