How can i test all scenarios of firstname and lastname

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjava
    New Member
    • Sep 2009
    • 132

    #1

    How can i test all scenarios of firstname and lastname

    I have this function i must test all scenarios of the firstname :
    Code:
    1-first scenarios if the firstname is empty .
    2-second scenarios if the firstname contains one character.
    3-third scenrarios if the firstname have two character.
    4-four scenarios if the firstname have Three character.
    5-other scenarios ...
    so here my function :

    Code:
    <?php
    $loginuser = $thirdpartycode .'_'. substr($firstname, 0, 1) .''. substr($lastname, 0, 1);
    echo 'login user GeneratedLogin:'. $loginuser;
    
    // $usercheck = new Admin_Model_DbTable_User();
    // $iduser=$usercheck->checkUser($loginuser);
    
    $firstnamex = 0;
    $firstnamey = 1;
    $lastnamex = 0;
    $lastnamey = 1;
    $max = 4;
    do {
        ++$firstnamey;
        ++$lastnamey;
        if (empty($firstname)) {
            $loginuser = $thirdpartycode .'_'. substr($lastname, $lastnamex, $lastnamey);
        }
        else {
            if (strlen($firstname) < $max) {
                $firstnamex = 0;
                $firstnamey = 1;
                $loginuser = $thirdpartycode .'_'. substr($firstname, $firstnamex, $firstnamey) . '' . substr($lastname, $lastnamex, $lastnamey);
            }
    
            $loginuser = $thirdpartycode .'_'. substr($firstname, $firstnamex, $firstnamey) . '' . substr($lastname, $lastnamex, $lastnamey);
        }
    
        $usercheck = new Admin_Model_DbTable_User();
        $iduser = $usercheck->checkUser($loginuser);
        if (($firstnamey == $max) && ($lastnamey == $max)) break;
    }
    
    while ($iduser > 0);
    error_log('login user GeneratedLogin:'. $loginuser);
    return $loginuser;
    please can you my script and tell me what can i update to take all scenarios.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that’s what Unit Tests are for.

    the most common library for that is PHPUnit.

    Comment

    • manjava
      New Member
      • Sep 2009
      • 132

      #3
      Thanks for your answer,but i need help about the scenarios if in the boucle while of the test the scenarios thanks in advance

      Comment

      Working...