Skip to content

Instantly share code, notes, and snippets.

@bgrimes
Created March 8, 2013 16:53
Show Gist options
  • Save bgrimes/5117930 to your computer and use it in GitHub Desktop.
Save bgrimes/5117930 to your computer and use it in GitHub Desktop.
<?php
/**
* PHPUnit style mocking:
*/
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
{
protected function getEmMock()
{
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
$emMock->expects($this->any())
->method('getRepository')
->will($this->returnValue(new FakeRepository()));
$emMock->expects($this->any())
->method('getClassMetadata')
->will($this->returnValue((object)array('name' => 'aClass')));
$emMock->expects($this->any())
->method('persist')
->will($this->returnValue(null));
$emMock->expects($this->any())
->method('flush')
->will($this->returnValue(null));
return $emMock; // it tooks 13 lines to achieve mock!
}
}
/**
* Mockery style:
*/
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
{
protected function getEmMock()
{
$emMock = \Mockery::mock('\Doctrine\ORM\EntityManager',
array(
'getRepository' => new FakeRepository(),
'getClassMetadata' => (object)array('name' => 'aClass'),
'persist' => null,
'flush' => null,
));
return $emMock; // it tooks 6 lines, yay!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment