Forked from wowo/PHPUnit way to mock Doctrine2 Entity Manager.php
Last active
August 26, 2015 03:48
-
-
Save hkulekci/1e9280d87dc83561c111 to your computer and use it in GitHub Desktop.
PHPUnit's way to mock Doctrine2 Entity Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment