PHP: “Mocking” built-in functions like time() in Unit Tests

Dieser Artikel ist nur auf Englisch erschienen.

11 Replies to “PHP: “Mocking” built-in functions like time() in Unit Tests”

  1. This looks excellent. The cleanest way to mock time that I have seen so far !
    Thanks a lot for the tip 🙂

  2. I liked this strategy so much… I pushed it a little further down the line 🙂

    In this post in programmers stackexchange I was searching for a way to organize my tests.

    I finally implemented a solution following the steps you describe in this page, overriding the DateTime() function. Available here for the curious 🙂

    Thanks again !

  3. “Important Implication: It does not work if you use the global functions with fully qualified names (i.E. \time()) in your test subjects!”

    So, any ideas on how to test when the fully qualified name is used?

  4. Huge help! Made it easy to essentially “disable” the mail() function in our Email class by simply returning true when the mail() function is called.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *