Skip to content

Instantly share code, notes, and snippets.

@robertbasic
Created September 13, 2012 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertbasic/3717485 to your computer and use it in GitHub Desktop.
Save robertbasic/3717485 to your computer and use it in GitHub Desktop.
Zend\Db\Adapter\Adapter mocking with mockery
<?php
protected function getAdapterMock()
{
$adapter = m::mock('Zend\Db\Adapter\Adapter');
$platform = m::mock('Zend\Db\Adapter\Platform\Mysql[getName]');
$stmt = m::mock('Zend\Db\Adapter\Driver\Pdo\Statement');
$paramContainer = m::mock('Zend\Db\Adapter\ParameterContainer');
$platform->shouldReceive('getName')
->once()
->andReturn('MySQL');
$stmt->shouldReceive('getParameterContainer')
->once()
->andReturn($paramContainer);
$stmt->shouldReceive('setSql')
->once()
->andReturn($stmt);
$stmt->shouldReceive('execute')
->once()
->andReturn(array());
$adapter->shouldReceive('getPlatform')
->once()
->andReturn($platform);
$adapter->shouldReceive('createStatement')
->once()
->andReturn($stmt);
return $adapter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment