Example #1
0
 /**
  * 
  * @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'));
 }
Example #3
0
 /**
  * 
  * @param string $className
  * @return ClassMetadata
  */
 public function getClassMetadata($className)
 {
     return $this->metadataFactory->getMetadataFor(ltrim($className, '\\'));
 }
Example #4
0
 /**
  * 
  * @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;
 }