database testing in php using phpunit,simpletest on api haveing stored procedure

微笑、不失礼 提交于 2019-12-13 05:24:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!