最近刚进入 PHPUnit,一直在阅读有关它的内容,尝试了一些示例,以便在为我未来的项目编写测试时感到舒服。
我需要测试这种情况,我有学生类,如下所示:
class Students
{
public function getStudents($studentName, $studentId)
{
$students= array();
//Instantiating OldStudent Class from Old Project
$oldStudents = \OldStudents::getStudentByName($studentName, $studentId);
//Create a Student Object for every OldStudent found on Old Project and set
//values
foreach ($oldStudents as $oldStudent)
{
$student = new \Entity\Student();
//Set Student ID
$student->setStudentId($oldStudent->getStudentID());
//Set Student Name
$student->setStudentName($oldStudent->getStudentName());
//.....other setters for student data, irrelevant for this example
$students[] = $student;
}
return $students;
}
}
还有学生班
Class Student
{
protected $studentId;
protected $studentName;
public function getStudentId()
{
return $this->studentId;
}
public function setStudentId($studentId)
{
$this->studentId = $studentId;
return $this;
}
public function getStudentName()
{
return $this->studentName;
}
public function setStudentName($studentName)
{
$this->studentName = $studentName;
return $this;
}
}
现在我如何测试学生类是否返回具有值集的对象数组并检查使用学生类的getter的值
请务必抛出一些光/信息/链接,以引导我走上正确的道路。
谢谢