class RemoteConnect
{
public function connectToServer($serverName=null)
{
if($serverName==null){
throw new Exception(“That's not a server name!”);
}
$fp = fsockopen($serverName,80);
return ($fp) ? true : false;
}
public function returnSampleObject()
{
return $this;
}
}
?>
下面的代码实际上是完成毗连到一个指定的办事器的功效,那末咱们可以编写测试代码以下:
require_once('RemoteConnect.php');
class RemoteConnectTest extends PHPUnit_Framework_TestCase
{
public function setUp(){ }
public function tearDown(){ }
public function testConnectionIsValid()
{
// test to ensure that the object from an fsockopen is valid
$connObj = new RemoteConnect();
$serverName = 'www.谷歌.com';
$this->assertTrue($connObj->connectToServer($serverName) !== false);
}
}
?>
class CommentControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
}
public function appBootstrap()
{
$this->frontController->registerPlugin(new Initializer('test'));
}
public function testGoHome()
{
$this->dispatch('/home');
$this->assertController('home');
}
}
?>