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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.