title: PHPUnit: How to mock an internally called function by the method under test
body: <p>In the below example, I want to mock the calling of <code>getBaseValue()</code> inside the <code>multipliedValue()</code>. But I cannot figure it out.</p>
  
  <pre><code>class Sample
  {
      function multipliedValue()
      {
        $value = $this-&gt;getBaseValue();
        return $value * 2;
      }
  
      function getBaseValue()
      {
        return 2;
      }
  }
  </code></pre>
  
  <p>I have used PHPUnit mocking, but it didn't work. So, I used the following code:</p>
  
  <pre><code>class SampleTest extends PHPUnit_Framework_TestCase
  {
    function testMultipliedValueIfBaseValueIsFalse()
    {
          $mockedObject = $this-&gt;getMockBuilder(Sample::class)
              -&gt;setMethods(['multipliedValue', 'getBaseValue'])
              -&gt;getMock();
          $mockedObject-&gt;expects($this-&gt;any())
              -&gt;method("getBaseValue")
              -&gt;willReturn(false);
          $result = $mockedObject-&gt;multipliedValue();
          $this-&gt;assertFalse($result);
    }
  }
  </code></pre>
  
  <p>I tried to create a global function, but only force one of the method to return my desired value, the rest just go as they are. How should I approach this test?</p>
  
  <p>The error I am currently getting is for the <code>$this</code> in the <code>multipliedValue()</code> method, which treats it as the stubbed object.</p>