控制器的 PHP 单元测试不返回任何错误,也没有成功消息
我正在使用 zend 模块化导向器结构,即
application
modules
users
controllers
.
.
lessons
reports
blog
我对“博客”中的控制器进行了单元测试,其类似于以下代码部分: 我肯定做了一些非常错误的事情,或者遗漏了一些东西 - 当我运行测试时,我没有收到错误,没有成功消息(通常像...好的(2个测试,2个断言))。 我从layout.phtml 中获取所有文本,其中有全局站点布局。
这是我第一次尝试为 zend-MVC 结构编写单元测试,所以我可能遗漏了一些重要的东西?
这里....
require_once '../../../../public/index.php';
require_once '../../../../application/Bootstrap.php';
require_once '../../../../application/modules/blog/controllers/BrowseController.php';
require_once '../../../TestConfiguration.php';
class Blog_BrowseControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp() {
$this->bootstrap = array($this, 'appBootstrap');
Blog_BrowseController::setUp();
}
public function appBootstrap() {
require_once dirname(__FILE__) . '/../../bootstrap.php';
}
public function testAction() {
$this->dispatch('/');
$this->assertController('browse');
$this->assertAction('index');
}
public function tearDown() {
$this->resetRequest();
$this->resetResponse();
Blog_BrowseController::tearDown();
}
}
I'm using the zend modular director structure, i.e.
application
modules
users
controllers
.
.
lessons
reports
blog
I have a unit test for a controller in 'blog' that goes something like the below section of code:
I'm definitely doing something very wrong, or missing something - as when i run the test, i get no error, no success message (that goes usually like ...OK (2 tests, 2 assertions)).
I get all the text from layout.phtml, where i have the global site layout.
This is my first endeavor writing a unittest for zend-M-V-C structure so probably I'm missing something important?
Here goes....
require_once '../../../../public/index.php';
require_once '../../../../application/Bootstrap.php';
require_once '../../../../application/modules/blog/controllers/BrowseController.php';
require_once '../../../TestConfiguration.php';
class Blog_BrowseControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp() {
$this->bootstrap = array($this, 'appBootstrap');
Blog_BrowseController::setUp();
}
public function appBootstrap() {
require_once dirname(__FILE__) . '/../../bootstrap.php';
}
public function testAction() {
$this->dispatch('/');
$this->assertController('browse');
$this->assertAction('index');
}
public function tearDown() {
$this->resetRequest();
$this->resetResponse();
Blog_BrowseController::tearDown();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
public/index.php
文件是用于引导应用程序以进行 Web 查看的脚本。我认为您不应该将其包含在测试脚本中。此外,您可以通过引用 APPLICATION_PATH 来避免所有这些相对路径。The
public/index.php
file is the script used to bootstrap your application for web viewing. I don't think you should be including it in your test script. Also, you can avoid all of those relative paths by referencingAPPLICATION_PATH
.