【问题标题】:database testing in php using phpunit,simpletest on api haveing stored procedure使用phpunit在php中进行数据库测试,对具有存储过程的api进行简单测试
【发布时间】:2014-02-13 13:23:19
【问题描述】:

我如何使用 phpunit 进行数据库测试,我已经对此进行了 Google 搜索,但问题是,我的 api 正在调用存储过程以与 mysql 交互,而在 phpunit 中我无法在数据库 XML 上触发存储过程文件

请检查一下

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

我必须为每个存储过程调用创建一个 XML 文件来检查结果(比较结果)

有没有其他方法可以解决这个问题 我可以使用 simpletest 以简单的方式实现这一目标吗

请回复朋友ZZzz

【问题讨论】:

    标签: php stored-procedures phpunit dbunit simpletest


    【解决方案1】:

    有示例代码如何在 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();
     }
    

    【讨论】:

    • 感谢您的回答,它对我非常有用
    猜你喜欢
    • 2011-06-02
    • 2014-08-02
    • 1970-01-01
    • 2018-09-12
    • 2011-10-10
    • 2015-01-27
    • 2011-05-14
    • 2010-11-04
    • 2014-02-26
    相关资源
    最近更新 更多