【发布时间】:2012-03-16 17:43:49
【问题描述】:
我有长期的编程经验,并决定在我的下一个项目中使用单元测试。我正在使用带有 CodeIgniter 和 oracle 的 php 作为 rdbms 创建一个应用程序。 我所有的模型基本上只有与数据库一起使用的方法:CRUD 方法,没什么特别的。好的,所以问题是我应该如何测试这些?它们值得测试吗?因为当查询错误时,我会得到一个 php 错误,基本上我所有的测试都会通过,因为我的查询是正确的。 在测试模型时我应该关注什么以及我应该期待什么?
例如: 简单的方法:
public function register($username, $password, $email)
{
$hash = $this->_generate_hash();
return $this->add(array(
'username' => $username,
'password' => hash('sha256', $this->config->item('salt') . $password . $hash),
'email' => $email,
'hash' => $hash
));
如果查询正常,则此插入将始终有效,并且如果我将测试参数添加到函数中,它将始终通过,但是由于 SQL 正常,因此测试通过了,或者我应该如何测试呢? }`
【问题讨论】:
标签: php model-view-controller unit-testing phpunit