|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Intracto\SmartCodeBundle\Tests; |
| 4 | + |
| 5 | +/** |
| 6 | + * Test case class helpful with Entity tests requiring the database interaction. |
| 7 | + * For regular entity tests it's better to extend standard \PHPUnit_Framework_TestCase instead. |
| 8 | + */ |
| 9 | +abstract class BaseTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + protected $entityManager; |
| 12 | + |
| 13 | + /** |
| 14 | + * @return null |
| 15 | + */ |
| 16 | + public function setUp() |
| 17 | + { |
| 18 | + $this->entityManager = $this->createLoadedMockedDoctrineRepository('AppBundle', 'SmartCodeBundle:SmartCode', 'findOneBy', null); |
| 19 | + parent::setUp(); |
| 20 | + } |
| 21 | + |
| 22 | + protected function createLoadedMockedDoctrineRepository($repository, $repositoryName,$repositoryMethod,$repositoryMethodReturnVal) { |
| 23 | + $mockEM=$this->getMock('\Doctrine\ORM\EntityManager', |
| 24 | + array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false); |
| 25 | + $mockSVRepo=$this->getMock($repository,array($repositoryMethod),array(),'',false); |
| 26 | + |
| 27 | + $mockEM->expects($this->any()) |
| 28 | + ->method('getClassMetadata') |
| 29 | + ->will($this->returnValue((object)array('name' => 'aClass'))); |
| 30 | + $mockEM->expects($this->any()) |
| 31 | + ->method('persist') |
| 32 | + ->will($this->returnValue(null)); |
| 33 | + $mockEM->expects($this->any()) |
| 34 | + ->method('flush') |
| 35 | + ->will($this->returnValue(null)); |
| 36 | + |
| 37 | + $mockSVRepo |
| 38 | + ->expects($this->any()) |
| 39 | + ->method($repositoryMethod) |
| 40 | + ->will($this->returnValue($repositoryMethodReturnVal)); |
| 41 | + |
| 42 | + $mockEM->expects($this->any()) |
| 43 | + ->method('getRepository') |
| 44 | + ->with($repositoryName) |
| 45 | + ->will($this->returnValue($mockSVRepo)); |
| 46 | + |
| 47 | + return $mockEM; |
| 48 | + } |
| 49 | +} |
0 commit comments