0

I am new to PHPUnit & unit-testing in general, I have got this problem, thankfully I can sense, the answer is out there, maybe with everyone has ever done their first tests.

Here it goes:
I have been trying to find tutorials for unit-testing with PHPUnit. And, so far all, I found were similar tutorials, in which they all used assertEquals() function to test if a method from class output was as expected or not.

like in this tutorial
http://www.sitepoint.com/tutorial-introduction-to-unit-testing-in-php-with-phpunit/
and
phpmaster.com/getting-started-with-phpunit/
It just shows a simple example for comparing expected and actual strings from a method.

OK! I get that, but so far all it does is compare strings. Simply, I'm looking for more.

So, to better illustrate my problem, lets imagine I have a class called class userLogin

I have simplified it, just so you can get the idea and its purpose.

class userLogin{

    function checkAlreadyLoggedIn($session){
        //if user is logged in say something
    }

    function checkVaidEmail($email){
        //if email is invalid throw error
    }

    function checkPassword($pass){
        //if pass is empty, then do something
    }

    function checkFromDb($email, $pass){
        //if user is found, set session else show message
    }
}

Now, my question is, in what possible ways can I test this class or its methods. What sounds logic enough here to test. Or, what could unexpectedly go wrong in this class, that I would need to test something from it? And if so, using what functions?

2
Contributors
1
Reply
21
Views
4 Years
Discussion Span
Last Post by pritaeas
0

what could unexpectedly go wrong in this class

When testing checkAlreadyLoggedIn do not test only with a session that would return true and one that would return false. Consider the fact that the session you pass as a parameter is invalid: NULL for example, but other situations may also be possible.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.