title: PHPUnit: How to test a method which calls another function declared in different file
body: <p>I'm trying to test a method using PHPUnit, where it calls another function (<em>standalone function, without class</em>), which resides in different file which does a some pretty good calculation and returns a object.</p>
  
  <p>This is my actual main code:</p>
  
  <pre><code>class CreateRecords
  {
      public function createEntities($details)
      {
          if (trim($details['username']) == "") {
              $this-&gt;result = "Username is empty.";
          } else {
              $this-&gt;result = create_record($Details['username']);
          }       
          return $this-&gt;result;
      }
  }
  </code></pre>
  
  <p>This <code>create_record</code> function, (<em>standalone function, without class</em>), which is core function, resides in separate file and it does pretty good calculations (<em>calls lots of other methods/functions</em>) and returns object, whether it is successful or not.</p>
  
  <p>I can mock the <code>createEntities</code> method, but I want to mock the <code>create_record</code> function, which does all the computations and returns the result. </p>
  
  <p>I have seen few posts which has a somewhat similar scenario,</p>
  
  <p><a href="https://stackoverflow.com/questions/18264647/phpunit-testing-method-that-calls-other-class-methods-which-need-mock">phpunit testing method that calls other class methods which need mock</a></p>
  
  <p><a href="https://stackoverflow.com/questions/22678187/phpunit-mock-method-used-in-another-class">PHPUnit mock method used in another class</a></p>
  
  <p>But I am unable to understand, how to mock standalone function which is declared in some different file. </p>