title: PHPUnit: Mocking __get() results in "__get() must take exactly 1 argument ..."
body: <p>I've got a problem with mocking an overloaded __get($index) method.
  The code for the class to be mocked and the system under test that consumes it is as follows:</p>
  
  <pre><code>&lt;?php
  class ToBeMocked
  {
      protected $vars = array();
  
      public function __get($index)
      {
          if (isset($this-&gt;vars[$index])) {
              return $this-&gt;vars[$index];
          } else {
              return NULL;
          }
      }
  }
  
  class SUTclass
  {
      protected $mocky;
  
      public function __construct(ToBeMocked $mocky)
      {
          $this-&gt;mocky = $mocky;
      }
  
      public function getSnack()
      {
          return $this-&gt;mocky-&gt;snack;
      }
  }
  </code></pre>
  
  <p>Test looks as follows:</p>
  
  <pre><code>&lt;?php    
  class GetSnackTest extends PHPUnit_Framework_TestCase
  {
      protected $stub;
      protected $sut;
  
      public function setUp()
      {
         $mock = $this-&gt;getMockBuilder('ToBeMocked')
                       -&gt;setMethods(array('__get')
                       -&gt;getMock();
  
         $sut = new SUTclass($mock);
      }
  
      /**
       * @test
       */
      public function shouldReturnSnickers()
      {
          $this-&gt;mock-&gt;expects($this-&gt;once())
                     -&gt;method('__get')
                     -&gt;will($this-&gt;returnValue('snickers');
  
          $this-&gt;assertEquals('snickers', $this-&gt;sut-&gt;getSnack());
      }
  }
  </code></pre>
  
  <p>Real code is a little bit more complex, though not much, having "getSnacks()" in its parent class. But this example should suffice.</p>
  
  <p>Problem is I get the following error, when executing the test with PHPUnit:</p>
  
  <pre><code>Fatal error: Method Mock_ToBeMocked_12345672f::__get() must take exactly 1 argument in /usr/share/php/PHPUnit/Framework/MockObject/Generator.php(231)
  </code></pre>
  
  <p>When I debug I can't even reach the test method. It seems it breaks at setting up the mock object.</p>
  
  <p>Any ideas?</p>