Alex
Alex

Reputation: 478

Simple php UnitTtests but kind of stuck

i started few time ago to do some unit testings for my functions but i really can't find how to do it properly for this function. I think it's really easy but there's something i'm missing.

    /**
 * Tests model->function()
 */
public function testFunction() {
    // TODO Auto-generated model->testFunction()
    $this->markTestIncomplete ( "function test not implemented" );
    $this->model->testFunction('', '5');
    $this->model->testFunction('test', '');
    $this->model->testFunction('test', 'a');
    $this->model->testFunction('1', '5');

}

This is what i have and phpUnit just ignore those tests. What i want is to test my function (which needs 2 parameters, both integers) and check :

Can someone help me with this please?

Thanks a lot !

Upvotes: 1

Views: 54

Answers (1)

Steven Scott
Steven Scott

Reputation: 11250

The first statement

$this->markTestIncomplete ()

will cause PHPUnit to pass over this test file and mark it with an I in the output for not completed (executed).

Secondly, the format for your tests is incorrect. You need to create the object, then test it.

public function setUp()
{
    $this->model = new model();
}

public function testFunction()
{
    $this->assertEquals('test', $this->model->Function(5));  // Test what the function should return, using parameters replacing the 5
}

The Function should accept a parameter based on what I see in your attempt. Then this function will return something, that you can evaluate against.

Optionally, you can use a dataProvider to provide multiple values to the test and see the output. Check the PHPUnit manual for more information.

Upvotes: 1

Related Questions