1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

The headaches/confusions of unit testing with PHPUnit.

Discussion in 'PHP' started by eritrea1, Aug 11, 2013.

  1. #1
    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 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
        }
    }
    Code (markup):
    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?
     
    eritrea1, Aug 11, 2013 IP