title: how to mock global functions and classes used by another class
body: <p>I am trying to write a test, and one of my methods makes use of a global function <code>web()</code> which takes a (string) url, and creates and returns new instance of <code>UrlHelper</code>. This gives my app some shortcuts to some helper methods. (Yes DI would be better, but this is in a larvel app...)</p>
  
  <p>The method I'm trying to test, uses this global helper to get the content of the given url and compares it to another string.</p>
  
  <p>Using phpunit, how can i intercept the call to <code>web</code> or the creation of <code>UrlHelper</code> so i can ensure it returns a given response? the code looks a bit like the following</p>
  
  <pre><code>function web($url){
   return new \another\namespace\UrlUtility($url);
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>namespace some/namespace;
  
  class checker {
     function compare($url, $content){
         $content = web($url)-&gt;content();
         ...logic...
         return $status;
     }
  }
  </code></pre>
  
  <p>The unit test is testing the logic of compare, so i want to get expected content from the <code>web</code> call. I was hoping mocks/stubs would do the trick - but I'm not sure if i can hit this global function or another class which isn't passed in?</p>
  
  <p>Thanks</p>