41 php testing phpunit unit-testing zend-framework
我想知道如何用Zend_Test编写PHPUnit测试,一般用PHP编写.
Ste*_*rig 14
我正在使用Zend_Test来完全测试所有控制器.设置起来非常简单,因为您只需要设置引导程序文件(引导文件本身不应该调度前端控制器!).我的基本测试用例类如下所示:
abstract class Controller_TestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
protected function setUp()
{
$this->bootstrap=array($this, 'appBootstrap');
Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_NonPersistent());
parent::setUp();
}
protected function tearDown()
{
Zend_Auth::getInstance()->clearIdentity();
}
protected function appBootstrap()
{
Application::setup();
}
}
Run Code Online (Sandbox Code Playgroud)
在那里Application::setup();确实这也创下了实际应用中的所有设置了任务.然后一个简单的测试看起来像这样:
class Controller_IndexControllerTest extends Controller_TestCase
{
public function testShowist()
{
$this->dispatch('/');
$this->assertController('index');
$this->assertAction('list');
$this->assertQueryContentContains('ul li a', 'Test String');
}
}
Run Code Online (Sandbox Code Playgroud)
就这样...
| 归档时间: |
|
| 查看次数: |
25238 次 |
| 最近记录: |