Exemplo n.º 1
0
 public function testRepositoryFactory()
 {
     $config = new Configuration();
     $this->assertInstanceOf('Pasinter\\OHM\\Repository\\DefaultRepositoryFactory', $config->getRepositoryFactory());
     $config->setRepositoryFactory($this->getMock('Pasinter\\OHM\\Repository\\RepositoryFactoryInterface'));
     $this->assertInstanceOf('Pasinter\\OHM\\Repository\\RepositoryFactoryInterface', $config->getRepositoryFactory());
 }
Exemplo n.º 2
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'));
 }
Exemplo n.º 4
0
 protected function setUp()
 {
     if (!$this->storage) {
         $this->storage = $storage = new RedisStorage([]);
         $this->storage->getRedis()->flushall();
         $this->storage->getRedis()->config('SET', 'stop-writes-on-bgsave-error', 'no');
     }
     if (!$this->em) {
         $configuration = new Configuration();
         $configuration->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), __DIR__ . '/../../Mocks/Entity/'));
         $this->em = new EntityManager($this->storage, $configuration);
     }
 }
Exemplo n.º 5
0
 public function getProxyFactory()
 {
     if (null === $this->proxyFactory) {
         $this->proxyFactory = new ProxyFactory($this, $this->config->getProxyDir(), $this->config->getProxyNamespace(), $this->config->getAutoGenerateProxyClasses());
     }
     return $this->proxyFactory;
 }
Exemplo n.º 6
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;
 }