What are standard/best practices for creating unit tests for functionality using databases?

后端 未结 3 1089
慢半拍i
慢半拍i 2021-02-02 14:34

I get the idea behind unit testing however am trying to think of a clean simple way do it when it requires database functionality. For instance I have a function that return re

3条回答
  •  粉色の甜心
    2021-02-02 15:18

    There is a whole chapter on that in the PHPUnit manual:

    • http://www.phpunit.de/manual/current/en/database.html and also worth reading
    • http://matthewturland.com/2010/01/04/database-testing-with-phpunit-and-mysql/

    It's like with everything else when Unit-Testing. Create a known state and test your code against it to see if it returns the expected results.

提交回复
热议问题