title: phpunit: mock object not fooling php
body: <p>I'm going through the <a href="http://framework.zend.com/manual/2.0/en/user-guide/database-and-models.html" rel="noreferrer">zend tutorials</a> and I am testing a class with a mock object with phpunit. When I pass a mock created from Zend\Db\TableGateway to my class, who's constructor expects a Zend\Db\TableGateway, I get an type error: </p>
  
  <pre><code>"...Argument 1 passed to Album\Model\AlbumTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, instance of Mock_TableGateway_65b55cb0 given..."
  </code></pre>
  
  <p>Is this supposed happen? Are phpunit mock objects supposed to be able to "fool" the class?</p>
  
  <p>Here is the real class:</p>
  
  <pre><code>class AlbumTable {
      protected $tableGateway;
  
      public function __construct(TableGateway $tableGateway) {
          $this-&gt;tableGateway = $tableGateway;
      }
  
      public function fetchAll() {
          $resultSet = $this-&gt;tableGateway-&gt;select();
          return $resultSet;
      }
  
      public function getAlbum($id){
          $id = (int) $id;
          $rowset = $this-&gt;tableGateway-&gt;select(array('id' =&gt; $id));
          $row = $rowset-&gt;current();
          if(!$row) {
              throw new \Exception("Couldn't find row: $id");
          }
          return $row;
      }
  
      public function saveAlbum(Album $album) {
          $data = array(
              'artist' =&gt; $album-&gt;artist,
              'title' =&gt; $album-&gt;title,
          );
  
          $id = (int)$album-&gt;id;
          if ($id == 0) {
              $this-&gt;tableGateway-&gt;insert($data);
          } else {
              if ($this-&gt;getAlbum($id)) {
                  $this-&gt;tableGateway-&gt;update($data, array('id' =&gt; $id));
              } else {
                  throw new \Exception('Form id does not exist');
              }
          }
      }
  
      public function deleteAlbum($id) {
          $this-&gt;tableGateway-&gt;delete(array('id' =&gt; $id));
      }
  
  }
  </code></pre>
  
  <p>and the test:</p>
  
  <pre><code>class AlbumTableTest extends PHPUnit_Framework_TestCase {
      public function testFetchAllReturnsAllAlbums() {
          $resultSet = new ResultSet();
          $mockTableGateway = $this-&gt;getMock('Zend\Db\TableGateway',
              array('select'), array(), '', false);
  
          $mockTableGateway-&gt;expects($this-&gt;once())
              -&gt;method('select')
              -&gt;with()
              -&gt;will($this-&gt;returnValue($resultSet));
  
          $albumTable = new AlbumTable($mockTableGateway);
          $this-&gt;assertSame($resultSet, $albumTable-&gt;fechAll());
      }
  }
  </code></pre>
  
  <p>and the error:</p>
  
  <pre><code>Time: 102 ms, Memory: 5.00Mb
  
  There was 1 error:
  
  1) AlbumTest\Model\AlbumTableTest::testFetchAllReturnsAllAlbums
  Argument 1 passed to Album\Model\AlbumTable::__construct() must be an instance of Zend\Db\TableGateway\TableGateway, instance of Mock_TableGateway_65b55cb0 given, called in C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\test\AlbumTest\Model\AlbumTableTest.php on line 20 and defined
  
  C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\src\Album\Model\AlbumTable.php:9
  C:\Users\MEEE\Google Drive\code\iis\www\CommunicationApp\module\Album\test\AlbumTest\Model\AlbumTableTest.php:20
  
  FAILURES!
  Tests: 4, Assertions: 9, Errors: 1.
  </code></pre>