以下代码:
function personInfo($person)
{
$zipCode="12345";
if($zipCode!=54321)
{
$zipCode="12345";
$postal="World";
if($zipCode AND $postal < 1)
{
return "Wrong";
}
//Test stops here and do not continue???
}
$person->firstname="Mike";
$person->lastname="Wayne";
$person->address="Universe";
$person->zipCode="12345";
$person->mobile="123456789784512";
$person->password="GogoGO";
$person->socialSecurityNumber="1234567891234567";
return "OK";
}
我不知道为什么它会停在那里,因为我想在代码失败时测试代码,以及什么时候可以。我还在学习,所以我会非常感谢所有的帮助!
连接到&#34;函数personInfo($ person)&#34;的其余代码(数据库和测试):
function personInfo($person)
{
$this->db->autocommit(false);
$sql = "Select * from Postal Where ZipCode = '$person->zipCode'";
$result = $this->db->query($sql);
if($this->db->affected_rows!=1)
{
$sql = "Insert Into Postal (ZipCode, Postal) Values ('$person->zipCode','$person->postal')";
$result = $this->db->query($sql);
if($this->db->affected_rows < 1)
{
$this->db->rollback();
return "Wrong";
}
}
$sql .= "Update Person Set Firstname = '$person->firstname', Lastname = '$person->lastname',";
$sql .= " Address = '$person->address', ZipCode = '$person->zipCode',";
$sql .= " Mobile = '$person->mobile', Password ='$person->password'";
$sql .= " Where SocialSecurityNumber = '$person->socialSecurityNumber'";
$result = $this->db->query($sql);
$this->db->commit();
return "OK";
}
class personInfoTest extends PHPUnit_Framework_TestCase {
public function testPersonInfoWrong()
{
//arrange
$zipCode="1234";
$person=$zipCode;
$record=new Record(new DBStub());
// act
$result= $record->personInfo($person);
//assert
$this->assertEquals("Wrong",$result);
}
public function testPersonInfoOK()
{
//arrange
$zipCode="1234";
$person=$zipCode;
$record=new Record(new DBStub());
// act
$result= $record->personInfo($person);
// assert
$this->assertEquals("OK",$result);
$this->assertEquals("1234567891234567",$result->socialSecurityNumber);
$this->assertEquals("Mike",$result->firstname);
$this->assertEquals("Wayne",$result->lastname);
$this->assertEquals("Universe",$result->address);
$this->assertEquals("1234567812345",$result->telefonnr);
$this->assertEquals("GogoGO",$result->password);
$this->assertEquals("12345",$result->zipCode);
$this->assertEquals("World",$result->poststed);
}
}