title: PHPUnit and namespaces - mocked methods still being called
body: <p>I am adding unit tests to an existing project that is using namespaces. I haven't ever had to use namespaces before, so it is somewhat of an adventure. My issue is that in my unit tests, it appears the mocked methods are still being called. Below is an example of the code file and the test.</p>
  
  <pre><code>private function selectFromDb($fields, $criteria = null) {
      $fields = is_array($fields) ? implode(', ', $fields) : $fields;
  
      $sql = "SELECT $fields FROM balloons";
  
      if(!is_null($criteria)) {
          $sql .= " WHERE $criteria";
      }
  
      $adapter = $this-&gt;getAdapter();
      $statement = $adapter-&gt;query($sql);
      $result = $statement-&gt;execute();
  
      return $result;
  }
  </code></pre>
  
  <p>Here is the test code:</p>
  
  <pre><code>// I'm passing in data here which isn't consequential for the question.
  public function testSelectFromDb($fields, $criteria, $expectedSql) {
      $statement = $this-&gt;getMockBuilder('Zend\Db\Adapter\Driver\Pdo\Statement')
          -&gt;disableOriginalConstructor()
          -&gt;setMethods(array('execute'))-&gt;getMock();
      $statement-&gt;expects($this-&gt;once())
          -&gt;method('execute')-&gt;will($this-&gt;returnValue('fake'));
  
      $adapter = $this-&gt;getMockBuilder('Zend\Db\Adapter\Adapter')
          -&gt;disableOriginalConstructor()
          -&gt;setMethods(array('query'))-&gt;getMock();
      $adapter-&gt;expects($this-&gt;once())
          -&gt;method('query')-&gt;with($expectedSql)
          -&gt;will($this-&gt;returnValue($statement));
  
      $bm = $this-&gt;getMockBuilder('Application\Model\BalloonModel')
          -&gt;setMethods(array('getAdapter'))
          -&gt;disableOriginalConstructor()-&gt;getMock();
      $bm-&gt;expects($this-&gt;once())
          -&gt;method('getAdapter')-&gt;will($this-&gt;returnValue($adapter));
  
      // I use reflection as the method is private to the class
      $reflection = new ReflectionClass($bm);
      $method = $reflection-&gt;getMethod('selectFromDb');
      $method-&gt;setAccessible(true);
  
      $result = $method-&gt;invokeArgs($bm, array($fields, $criteria));
  
  }
  </code></pre>
  
  <p>At this point, I'm just trying to get the test to execute to the end, but I continue to get the following error: </p>
  
  <pre><code>Tests\Model\BalloonModelTest::testSelectFromDb with data set "singleField" ('id', NULL, 'SELECT id FROM balloon')
      Zend\Db\Adapter\Exception\InvalidQueryException: Statement could not be executed
  
  /apath/PHP/vendor/zendframework/zendframework/library/zend/db/adapter/driver/pdo/statement.php:245
  /apath/PHP/vendor/zendframework/zendframework/library/zend/db/adapter/driver/pdo/statement.php:240
  /apath/PHP/module/Application/src/application/model/balloonmodel.php:243
  /apath/PHP/tests/Model/BalloonModelTest.php:70
  
  Caused by
  PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list' 
  
  /apath/PHP/vendor/zendframework/zendframework/library/zend/db/adapter/driver/pdo/statement.php:240
  /apath/PHP/module/Application/src/application/model/balloonmodel.php:243
  /apath/PHP/tests/Model/BalloonModelTest.php:70
  </code></pre>
  
  <p>This tells me that the 'getAdapter', 'query' and 'execute' calls are still being made even though all of them are theoretically mocked. I've verified as best I can that the class names used are using the correct namespaces. Any ideas?</p>