0

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);
    }

}
2
  • The problem is the temp name part of the array. :facepalm: Commented May 15, 2012 at 14:11
  • 1
    Im getting following error: FileuploadTest::testFileupload Failed accerting that true is false.... and displaying error on this line = $this->assertFalse($testUpload->validate()); Commented May 16, 2012 at 5:46

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

ask for clarifications if needed
you are welcome, and do consider accepting the answer. check that link to know how accepting helps everyone. it'll give you and me reputation points, and also help future visitors know that the question is answered.
yes Mr. BOOL i have accepted your answer. sorry for late reply :) thanx again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.