/** * * @param StorageInterface $storageDriver * @param Configuration $config * @param EventManager $eventManager */ public function __construct(StorageInterface $storageDriver, Configuration $config, EventManager $eventManager = null) { $this->storageDriver = $storageDriver; $this->config = $config; $this->eventManager = $eventManager ?: new EventManager(); $metadataFactoryClassName = $this->config->getClassMetadataFactoryClassName(); $this->metadataFactory = new $metadataFactoryClassName(); $this->metadataFactory->setEntityManager($this); $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); $this->unitOfWork = new UnitOfWork($this); }
/** * * @return EntityManager */ private function getManager() { $config = new Configuration(); $config->setMetadataCacheImpl(new ArrayCache()); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), __DIR__ . '/../Mocks/Entity/')); $em = new EntityManager($this->getMock('Pasinter\\OHM\\Storage\\StorageInterface'), $config); $cmFactory = new ClassMetadataFactory(); $cmFactory->setEntityManager($em); return $em; }
public function test_getMetadataFor() { $cmFactory = new ClassMetadataFactory(); $emConfig = new Configuration(); $emConfig->setEntityNamespaces(['PasinterMocks' => 'Pasinter\\Mocks\\Entity']); $emConfig->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), __DIR__ . '/../../Mocks/Entity/')); $emConfig->setMetadataCacheImpl(new ArrayCache()); $cmFactory->setEntityManager(new EntityManager($this->getMock('Pasinter\\OHM\\Storage\\StorageInterface'), $emConfig)); $cmFactory->getAllMetadata(); $this->assertInstanceOf('Pasinter\\OHM\\Mapping\\ClassMetadata', $cmFactory->getMetadataFor('PasinterMocks:Blog\\Post')); }
/** * * @return UnitOfWork */ private function getUow(Changeset $cs = null) { $storage = $this->getMockBuilder('Pasinter\\OHM\\Storage\\AbstractStorage')->setConstructorArgs([[]])->setMethods(['storeScalar', 'storeSet', 'removeValuesFromSet', 'storeHash', 'delete', 'find', 'exists', 'getName', 'getVersion', 'allocateIds', 'beginTransaction', 'commit', 'rollback'])->getMock(); $storage->expects($this->any())->method('allocateIds')->willReturnCallback(function ($class, $number = 1) { static $ids = []; if (!isset($ids[$class])) { $ids[$class] = 1; } $ids[$class] = $ids[$class] + $number; return range($ids[$class] - $number, $number); }); $config = new Configuration(); $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), __DIR__ . '/../../Mocks/Entity/')); $em = $this->getMockBuilder('Pasinter\\OHM\\EntityManager')->setConstructorArgs([$storage, $config])->setMethods(['getClassMetadata'])->getMock(); $em->expects($this->any())->method('getClassMetadata')->will($this->returnValue(new PostClassMetadataMock())); $cmf = new ClassMetadataFactory(); $cmf->setEntityManager($em); $uow = new UnitOfWork($em); $uow->cs = $cs ?: new Changeset(); return $uow; }