title: phpunit testing method that calls other class methods which need mock
body: <p>I'm trying to create a pretty standard unit test where I call a method and assert it's response, however the method I'm testing calls another method inside the same class which does a little bit of heavy lifting. </p>
  
  <p>I want to mock that one method but still execute the method I'm testing as is, only with the mocked value returned from the call to the other method. </p>
  
  <p>I've dumbed down the example to make it as simple as possible.</p>
  
  <pre><code>class MyClass
  {
  
      // I want to test this method, but mock the handleValue method to always return a set value.
  
      public function testMethod($arg)
      {
  
          $value = $arg-&gt;getValue();
  
          $this-&gt;handleValue($value);
  
      }
  
  
      // This method needs to be mocked to always return a set value.
  
      public function handleValue($value)
      {
  
          // Do a bunch of stuff...
          $value += 20;
  
          return $value;
  
      }
  
  }
  </code></pre>
  
  <p>My attempt at writing the tests.</p>
  
  <pre><code>class MyClassTest extends \PHPUnit_Framework_TestCase
  {
  
  
      public function testTheTestMethod()
      {
  
          // mock the object that is passed in as an arg
          $arg = $this-&gt;getMockBuilder('SomeEntity')-&gt;getMock();
          $arg-&gt;expects($this-&gt;any())
              -&gt;method('getValue')
              -&gt;will($this-&gt;returnValue(10));
  
          // test handle document()
          $myClass = new MyClass();
  
          $result = $myClass-&gt;testMethod($arg);
  
          // assert result is the correct
          $this-&gt;assertEquals($result, 50);
  
      }
  
  }
  </code></pre>
  
  <p>I have tried mocking the MyClass object, but when I do that and call the testMethod it always returns null. I need a way to mock the one method but leave the rest of the object intact.</p>