title: Unit testing with mocks and reflections in PHPUnit
body: <p>I'm need to test protected method <code>testMethod</code> of class which uses some another method <code>mockMethod</code>. So I'm writing:</p>
  
  <pre><code>$class = $this-&gt;getMockBuilder('TestingClassName')
      -&gt;setMethods(['mockMethod'])
      -&gt;getMock();
  
  $class-&gt;expects($this-&gt;any())
      -&gt;method('mockMethod')
      -&gt;will($this-&gt;returnValue('Hey!'));
  
  $reflection = new \ReflectionObject($class);
      $method = $reflection-&gt;getMethod('testMethod');
      $method-&gt;setAccessible(true);
  
  $result = $method-&gt;invokeArgs($class, $paramsArray);
  </code></pre>
  
  <p>But when method <code>mockMethod</code> invokes inside of <code>testMethod</code> it becomes like not mocked. It's protected method too and if I invoke it with another <code>ReflectionMethod</code> - I will give 'Hey!' from it.</p>