久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='JERU6'></bdo><ul id='JERU6'></ul>

      <i id='JERU6'><tr id='JERU6'><dt id='JERU6'><q id='JERU6'><span id='JERU6'><b id='JERU6'><form id='JERU6'><ins id='JERU6'></ins><ul id='JERU6'></ul><sub id='JERU6'></sub></form><legend id='JERU6'></legend><bdo id='JERU6'><pre id='JERU6'><center id='JERU6'></center></pre></bdo></b><th id='JERU6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JERU6'><tfoot id='JERU6'></tfoot><dl id='JERU6'><fieldset id='JERU6'></fieldset></dl></div>

      <legend id='JERU6'><style id='JERU6'><dir id='JERU6'><q id='JERU6'></q></dir></style></legend>

      <small id='JERU6'></small><noframes id='JERU6'>

      1. <tfoot id='JERU6'></tfoot>

        使用數據庫進行 Phpunit 測試

        Phpunit testing with database(使用數據庫進行 Phpunit 測試)
        <tfoot id='F5sEx'></tfoot>
        • <small id='F5sEx'></small><noframes id='F5sEx'>

            <tbody id='F5sEx'></tbody>
          <legend id='F5sEx'><style id='F5sEx'><dir id='F5sEx'><q id='F5sEx'></q></dir></style></legend>
                <bdo id='F5sEx'></bdo><ul id='F5sEx'></ul>

              • <i id='F5sEx'><tr id='F5sEx'><dt id='F5sEx'><q id='F5sEx'><span id='F5sEx'><b id='F5sEx'><form id='F5sEx'><ins id='F5sEx'></ins><ul id='F5sEx'></ul><sub id='F5sEx'></sub></form><legend id='F5sEx'></legend><bdo id='F5sEx'><pre id='F5sEx'><center id='F5sEx'></center></pre></bdo></b><th id='F5sEx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='F5sEx'><tfoot id='F5sEx'></tfoot><dl id='F5sEx'><fieldset id='F5sEx'></fieldset></dl></div>

                1. 本文介紹了使用數據庫進行 Phpunit 測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 PHPunit 進行單元測試.

                  I am trying to focus a bit on unit testing using PHPunit.

                  我在這里找到了一個非常好的教程http://blog.nickbelhomme.com/php/phpunit-training-course-for-free_282

                  I have found a very good tutorial over here http://blog.nickbelhomme.com/php/phpunit-training-course-for-free_282

                  但是我遺漏了一些東西,我還不知道該怎么做.

                  But there is something I'm missing and don't yet understand how to do.

                  我有一個用戶模塊,用于維護有關用戶的所有信息.并且有一個函數 save 可以將用戶保存在數據庫中.所以我有一個 testFunction

                  I have a user module which maintains all information about users. And there is a function save which saves the user in the database. So I have a testFunction

                  public function testCanCreateUser()
                  {
                      $userData = array(
                          'userName'  =>  'User1',
                          'firstName' =>  'Joey',
                          'lastName'  =>  'Hendricks',
                          'email'     =>  'Joey@hendricks.com',
                          'password'  =>  'f$tfe8F'
                      
                      ); 
                      $user = new Model_User($userData);
                      $user->save();
                       
                  }
                  

                  我第一次運行測試時,這會起作用.因為數據庫是空的.但是當我第二次運行我的測試時它不會工作,因為我的系統不允許同一個用戶在數據庫中兩次.所以為了做到這一點,我必須在每次運行測試之前重新創建我的測試數據庫.這樣做的最佳方法是什么?

                  The first time when I will run my test this will work. Since the database is empty. But When I run my tests for the second time it won't work since my system doesn't allow the same user twice in the db. So In order to do this I have to recreate my testdatabase every time before I run my tests. What is the best way to do this?

                  或者這個問題可以用不同的方式解決嗎?

                  Or is this problem to be solved on a different way?

                  推薦答案

                  如果你想測試你的業務邏輯: Mock掉數據庫類并返回假數據

                  If you want to test your business logic: Mock away the Database class and return fake data

                  如果你想測試觸發 SQL 語句的類(恕我直言,你也可以測試它,因為我有點想知道我的代碼是否可以在后端的真實數據庫中正常工作)它會得到有點復雜,但有一些方法可以做到:

                  If you want to test the class that fires the SQL statements (and imho you could test that too since I kinda wanna know if my code works fine with a real db in the backend) it gets a little complicated but there are ways to do it:

                  • 在運行測試之前使用 setUp() 和 tearDown() 為您的數據獲得一致的狀態是(恕我直言)編寫數據庫驅動單元測試的好方法.不過,手動編寫大量自定義 sql 會很煩人.

                  • Using setUp() and tearDown() to get a consistent state for your data before running your tests is (imho) a fine way to write db-driven unittests. It can get annoying to write lots of custom sql by hand though.

                  為了讓您的生活更輕松,您可以查看 DbUnit 擴展 看看這是否適用于您的應用程序.

                  To make your life a little easier you can look into the DbUnit extension and see if that works for your Application.

                  如果您真的想深入了解 Unittesting 數據庫交互,關于該主題的最佳讀物是(恕我直言)Sebastian Bergmanns phpqa 書.

                  If you really want to dive into Unittesting database interactions the best read on the subject is (imho) the chapter on db-unittesting in Sebastian Bergmanns phpqa book.

                  您的應用程序是否可以允許自定義數據庫名稱和所有表的自動設置,也可以使用大量測試數據設置一次數據庫并在所有測試中使用該數據.盡管一個測試不依賴于另一個測試編寫的數據,但您可以小心.

                  Could your application allow for a custom database name and automated setup of all tables it may also be possible to set the db up once with a lot of testdata and use that data in all your tests. You could be carefull so though that one test doesn't rely on data written by another one.

                  這篇關于使用數據庫進行 Phpunit 測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <tfoot id='VST0F'></tfoot>
                    1. <i id='VST0F'><tr id='VST0F'><dt id='VST0F'><q id='VST0F'><span id='VST0F'><b id='VST0F'><form id='VST0F'><ins id='VST0F'></ins><ul id='VST0F'></ul><sub id='VST0F'></sub></form><legend id='VST0F'></legend><bdo id='VST0F'><pre id='VST0F'><center id='VST0F'></center></pre></bdo></b><th id='VST0F'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VST0F'><tfoot id='VST0F'></tfoot><dl id='VST0F'><fieldset id='VST0F'></fieldset></dl></div>

                        <tbody id='VST0F'></tbody>
                        <bdo id='VST0F'></bdo><ul id='VST0F'></ul>

                          <small id='VST0F'></small><noframes id='VST0F'>

                        1. <legend id='VST0F'><style id='VST0F'><dir id='VST0F'><q id='VST0F'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 免费黄色a视频 | 国产精品久久久久久模特 | 日韩视频精品在线 | 精品99爱视频在线观看 | 日日草夜夜草 | 欧美中文字幕一区二区三区 | 国产精品一区二区视频 | 成人在线观看免费爱爱 | 欧美激情精品久久久久久变态 | 麻豆av电影网 | 国产亚洲一区二区三区 | 在线日韩欧美 | 亚洲欧美日韩精品久久亚洲区 | av黄色免费在线观看 | 爱操影视| 亚洲自拍偷拍欧美 | 国产精品久久久久久久久久久久久久 | 91九色婷婷 | 久久久精品视频免费看 | 毛片免费观看视频 | 激情久久av一区av二区av三区 | 国产乱码精品一区二区三区中文 | 毛片久久久 | 国产精品国产精品 | 久久精品99国产精品 | 美女一区二区在线观看 | 成人av高清在线观看 | 久久久久国产精品 | 一级做受毛片免费大片 | 久久精品一区二区视频 | 日韩一及片 | 中文字幕免费视频 | 最近免费日本视频在线 | 在线观看免费av网 | 欧洲视频一区 | 综合久久99| 国产精品视频中文字幕 | 中文字字幕一区二区三区四区五区 | 不卡视频在线 | 国产精品不卡 | 国产精品高潮呻吟久久 |