I am writing unit tests for a symfony2 project. For example, I want to test some class that requires Doctrine \ ORM \ EntityManger inctance:
// Class for testing // ... class CategoryManager { public function __construct( EntityManager $em ) { // ...
So, I need to create an instance of Doctrine \ ORM \ EntityManager in my unit tests and pass it to the constructor as follows:
// Testing // ... $category1 = new Category(); $category2 = new Category(); $categories = array( $category1, $category2 ); $query = $this->getMock( '\Application\BackendBundle\Tests\Mocks\Doctrine\ORM\Query', array(), array(), '', false ); $query->expects( $this->any() ) ->method( 'getResult' ) ->will( $this->returnValue( $categories ) ); $em = $this->getMock( 'Doctrine\ORM\EntityManger', array(), array(), '', false ); $em->expects( $this->any() ) ->method( 'createQuery' ) ->will( $this->returnValue( $query ) ); // ...
Please help me advise how to improve and automate the creation of entity entities. I'm not sure if this is the right way to create bullying (creating these bulky layouts seems inconvenient to me). I will be happy for any advice.
source share