问题描述
我该如何使用phpunit进行数据库测试,我已经对此进行了Google搜索,但是问题是,我的api正在调用存储过程来与mysql交互,而在phpunit中,我无法在数据库XML上触发存储过程文件
how can i do database testing with phpunit, i have done Google search on this but the problem is, my api is calling an stored procedure to interact with mysql and in phpunit i am unable to fire an stored procedure on the database XML file
请检查此
https://stackoverflow.com/questions/21278242/phpunit-stored-procedure-database -测试
我必须为每个存储过程调用创建一个XML文件,以检查结果(比较结果)
And i have to create an XML file for every stored procedure call to check the result(compare the results) with it
是否有其他替代方法我可以使用simpletest以简单的方式实现这一目标吗?
is there any alternative way for thiscan i achieve this in a simple way using simpletest
请回复朋友ZZzz
推荐答案
这里有示例代码,您可以在phpunit中测试存储过程
there is the sample code how u can test stored procedure in phpunit
public function delete($userId)
{
// this function calls a stored procedure
$sql = "CALL Delete_User_Details(:userId)";
try {
$db = parent::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("userId", $userId);
$stmt->execute();
$id = $stmt->fetchObject();
if ($id == null) {
$delete_response->createJSONArray("DATABASE_ERROR",0);
} else {
$delete_response->createJSONArray("SUCCESS",1);
}
} catch (PDOException $e) {
$delete_response->createJSONArray("DATABASE_ERROR",0);
}
return $delete_response->toJSON();
}
这篇关于使用phpunit在php中进行数据库测试,在具有存储过程的api上进行简单测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!