Unit Test PHPUnit
<?PHP/** * Define a class to be tested Remoteconnect * @author JSON **/classremoteconnect{ Public functionConnectServer ($serverName=NULL){ if($serverName==NULL){ Throw New Exception("This was not a server name!"); } $fp=Fsockopen($serverName, 80); return $fp?true:false; } Public functionReturnsampleobject () {return $this; }}/** * Define a class to test remoteconnect, * but inherit phpunit_framework_testcase. * @author JSON * class name ends with Test * $this->asserttrue: Is the method of unit testing, there are many such methods. * Module installation and usage see PHPUnit official website. */classRemoteconnecttestextendsphpunit_framework_testcase{ Public functionsetUp () {} Public functionTearDown () {}//Test to ensure this from the object is valid. Public functionTestconnectisvalid () {Echo"Jaja"; Try{ $CONNOBJ=NewRemoteconnect (); $serverName=NULL; $this->asserttrue ($CONNOBJ->connectserver ($serverName) !==false); }Catch(Exception $e){ $e-GetMessage (); } } Public functiontestabc () {$this->asserttrue (3+2 = = 5); } }?>
PHPUnit Unit Test