title: PHP unit testing with external functions
body: <p>I'm trying to write unit tests for a PHP Wordpress project, but I'm struggling to grasp some of the concepts when it comes to mocking up external function calls and I'm not really sure what I need to do.</p>
  <p>Here is a very dumbed down version of the class I have created:</p>
  <pre><code>class Module
  {
     private $title;
  
     public __construct($id = false)
     {
        $this-&gt;title = get_the_title($id); // core wp function
     }
  
     public get_title()
     {
        return $this-&gt;title;
     }
  
  }
  </code></pre>
  <p>And I want to test it like so:</p>
  <pre><code>class ModuleTests extends TestCase
  {
     public test_get_title_returns_title_if_id()
     {
        $module = new Module(1);
        $this-&gt;assertSame($module-&gt;get_title(), 'A Test Title'); // should equal true
     }
  
     public test_get_title_returns_empty_string_if_no_id()
     {
        $module = new Module();
        $this-&gt;assertSame($module-&gt;get_title(), ''); // should equal true
     }
  }
  </code></pre>
  <p>Now obviously this doesn't work in isolation, because Module uses a core wordpress function in the constructor, so what is the correct method for testing in this scenario? Should I be replacing the global get_the_title() function with something that returns a hard coded value if the right arguments are passed to it? or is there some other way of doing this?</p>
  <p>I'm trying to drag myself away from the old wordpress procedural style PHP to use some more OOP practices for the bigger projects I work on but I'm still very new to it, so if I'm doing something completely wrong feel free to give constructive critisism as well.</p>
  <p>Also, I know that WP already has the template function the_title(), but I'm just using this as a simple example.</p>
  <p>Thanks in advance!</p>