0

Im new with unit-testing, I know how to test a function that contains two variables inside the functions, like this example, it contains "$user_id" and "$mysqli".

function checkbrute($user_id, $mysqli) {
   ...............
    }

And my question is, how do i test a function that looks like this? A function with no variables inside the function, it only contains the mysqli connection.

 function login_check($mysqli) {
    .......
    }

Thanks!!

4
  • Aren't both examples the same thing? Does the first function use a return statement to return the value of the two overloads to the function? Commented May 27, 2013 at 18:22
  • both of them return something, for the first example i have written this testcase: $LessThanFive = checkbrute('5', $mysqli); $this->assertFalse($LessThanFive); 5 is the $user_id. and mysqli the db connection. Commented May 27, 2013 at 18:25
  • I dont know how to set up a testcase for the 2nd example, could you please help me Commented May 27, 2013 at 18:25
  • I can certainly try to help, yes. I think if you are testing the Sql connection, you should do a comparison then assert what you are expecting like you are currently doing with the $userid variable. Commented May 27, 2013 at 19:09

1 Answer 1

1

Since you are passing in the $mysqli parameter as an overload to the function, wouldn't you be testing that connection object?

For example:

function login_check($mysqli) {    
    if ($mysqli == null)
       $this->AssertFalse($mysqli //there is no connection object);
    else
       $this->AssertTrue($mysqli //the connection string/object is what I am expecting);
    return $mysqli;
}

If you know what you are expecting in terms of the connection object, you basically just need to store it to a variable and compare the two.

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

3 Comments

Ehh, just saying, you should know, that any function stops its execution after return statement. So you got to perform everything before return.
Oops, I meant to move that down. Thank you for correcting that.
no im not testing the mysqli connection, inside function "login_check" there is code and a if, its comparing the db password with the password that a person enteres in. How do i compare them ? the statement return true/false.

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.