CakePHP 集成测试 - 还有其他要测试的东西吗?
CakePHP integration tests - Is there something else to test?
我的代码中有这样的方法。
public function businessDepartments()
{
$this->paginate = [
'conditions' => [
'Tags.tag_type_id' => 'businessDepartment'
]
];
parent::_index();
$this->set('columns', [
'tag_value' => ['title' => __d('cockpit', 'Business department')],
'sort' => ['title' => __d('cockpit', 'Sorting')]
]);
$this->_setURLsWhenAdd();
}
我可以使用 class "Tags" 和操作 "businessDepartment" 调用此方法。
这就是 _setURLWhenAdd() 的样子。
/**
* this method is setting the URLs inside the add
* @return setter
*/
protected function _setURLsWhenAdd()
{
// Set a new Url for the Add-Button in the index-View
$this->set('dataAjaxUrl', "/tags/add/businessDepartment");
// Sets the refreshable-Class on the element and the ajax-url where the element can get fresh data
$this->set('refreshable', '/tags/businessDepartments');
}
我有一个看起来像这样的测试。
public function testBusinessDepartments()
{
$this->get('/tags/businessDepartments');
$this->assertResponseOk();
}
这是我要测试的吗? Could/should 我再测试一下?除了此方法的入口和响应外?
Is this what I want to test ? Could/should I test something more ? Except entrance and response from this method ?
测试视图变量是否存在?
我认为在测试中应该可以通过 $this->_controller->viewVars
访问它们。如果不知道如何到达控制器实例。
另一种测试页面是否看起来和是否执行您除了它要做的事情的方法(明智的 JS)您也可以实施验收测试。请参阅 http://codeception.com/docs/03-AcceptanceTests Cake3 也有一个代码接收插件。
此外,您不应使用字符串 url /tags/businessDepartments
,而应使用 Router::url() 并使用数组语法。
我的代码中有这样的方法。
public function businessDepartments()
{
$this->paginate = [
'conditions' => [
'Tags.tag_type_id' => 'businessDepartment'
]
];
parent::_index();
$this->set('columns', [
'tag_value' => ['title' => __d('cockpit', 'Business department')],
'sort' => ['title' => __d('cockpit', 'Sorting')]
]);
$this->_setURLsWhenAdd();
}
我可以使用 class "Tags" 和操作 "businessDepartment" 调用此方法。 这就是 _setURLWhenAdd() 的样子。
/**
* this method is setting the URLs inside the add
* @return setter
*/
protected function _setURLsWhenAdd()
{
// Set a new Url for the Add-Button in the index-View
$this->set('dataAjaxUrl', "/tags/add/businessDepartment");
// Sets the refreshable-Class on the element and the ajax-url where the element can get fresh data
$this->set('refreshable', '/tags/businessDepartments');
}
我有一个看起来像这样的测试。
public function testBusinessDepartments()
{
$this->get('/tags/businessDepartments');
$this->assertResponseOk();
}
这是我要测试的吗? Could/should 我再测试一下?除了此方法的入口和响应外?
Is this what I want to test ? Could/should I test something more ? Except entrance and response from this method ?
测试视图变量是否存在?
我认为在测试中应该可以通过 $this->_controller->viewVars
访问它们。如果不知道如何到达控制器实例。
另一种测试页面是否看起来和是否执行您除了它要做的事情的方法(明智的 JS)您也可以实施验收测试。请参阅 http://codeception.com/docs/03-AcceptanceTests Cake3 也有一个代码接收插件。
此外,您不应使用字符串 url /tags/businessDepartments
,而应使用 Router::url() 并使用数组语法。