问题
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
please check this
https://stackoverflow.com/questions/21278242/phpunit-stored-procedure-database-testing
https://stackoverflow.com/questions/21230707/testing-stored-procedure-which-is-call-within-an-api-in-php-using-either-phpunit
And i have to create an XML file for every stored procedure call to check the result(compare the results) with it
is there any alternative way for this can i achieve this in a simple way using simpletest
please reply friend ZZzz
回答1:
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();
}
来源:https://stackoverflow.com/questions/21300665/database-testing-in-php-using-phpunit-simpletest-on-api-haveing-stored-procedure