createMock(MappingDriver::class); $mockMetadata = $this->createMock(ClassMetadata::class); $entityManager = $this->createMock(EntityManager::class); /* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */ $metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class) ->setMethods(['newClassMetadataInstance', 'wakeupReflection']) ->getMock(); $configuration = $this->getMockBuilder(Configuration::class) ->setMethods(['getMetadataDriverImpl']) ->getMock(); $connection = $this->createMock(Connection::class); $configuration ->expects($this->any()) ->method('getMetadataDriverImpl') ->will($this->returnValue($mockDriver)); $entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration)); $entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection)); $entityManager ->expects($this->any()) ->method('getEventManager') ->will($this->returnValue($this->createMock(EventManager::class))); $metadataFactory->expects($this->any())->method('newClassMetadataInstance')->will($this->returnValue($mockMetadata)); $metadataFactory->expects($this->once())->method('wakeupReflection'); $metadataFactory->setEntityManager($entityManager); $this->assertSame($mockMetadata, $metadataFactory->getMetadataFor(DDC2359Foo::class)); } } /** @Entity */ class DDC2359Foo { /** @Id @Column(type="integer") @GeneratedValue */ public $id; }