如何测试名字和姓氏的所有场景

时间:2015-09-21 10:45:13

标签: php

我有这个功能我必须测试名字的所有场景:

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 ...

所以我的功能:

<?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;

请问我的脚本并告诉我有什么可以更新以采取所有方案。

0 个答案:

没有答案