How do I write unit tests in PHP with a procedural codebase?

后端 未结 3 1809
清歌不尽
清歌不尽 2021-01-30 01:56

I\'m mostly convinced of the benefits of unit testing, and I would like to start applying the concept to a large existing codebase written in PHP. Less than 10% of this code is

3条回答
  •  醉梦人生
    2021-01-30 02:19

    You could try to include your non-oop code into a test class using

    require_once 'your_non_oop_file.php' # Contains fct_to_test()
    

    And with phpUnit you define your test function :

    testfct_to_test() {
       assertEquals( result_expected, fct_to_test(), 'Fail with fct_to_test' );
    }
    

提交回复
热议问题