예제 #1
0
 public function test__construct()
 {
     $metadata = new ClassMetadata(__NAMESPACE__ . '\\ModelTest');
     $metadata->addModel('entity', __NAMESPACE__ . '\\EntityTest');
     $metadata->setIdentifier('entity', 'id');
     $metadataFactory = $this->getMock('Pok\\PoolDBM\\Mapping\\ClassMetadataFactory', array('getMetadataFor', 'setModelManager'));
     $metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
     $refl = new \ReflectionClass('Pok\\PoolDBM\\Manager\\BaseManager');
     $this->assertTrue($refl->isInstantiable());
     $pool = new Pool();
     $pool->addManager('entity', new EntityManager());
     $manager = new TestManager(__NAMESPACE__ . '\\ModelTest', new ModelManager($pool, $metadataFactory));
     $this->assertInstanceOf('Pok\\PoolDBM\\ModelRepository', $manager->getRepository($manager));
     $this->assertInstanceOf(__NAMESPACE__ . '\\ModelTest', $manager->create());
     $manager->save(new ModelTest());
     $manager->save(new ModelTest(), true);
     try {
         $manager->save(new \stdClass());
     } catch (\RuntimeException $e) {
         $this->assertEquals('Manager "Pok\\PoolDBM\\Tests\\Manager\\TestManager" is unable to save model "stdClass"', $e->getMessage());
     }
     $manager->clear();
     $this->assertInstanceOf(__NAMESPACE__ . '\\ModelTest', $manager->find(null));
     $this->assertEquals(1, count($manager->findBy(array())));
     $this->assertInstanceOf(__NAMESPACE__ . '\\ModelTest', $manager->findOneBy(array()));
     $this->assertEquals(1, count($manager->findAll()));
 }
예제 #2
0
 public function test__construct()
 {
     $metadata = new \Pok\PoolDBM\Mapping\ClassMetadata(__NAMESPACE__ . '\\ModelTest');
     $metadata->addModel('entity', __NAMESPACE__ . '\\EntityTest', array());
     $metadata->setIdentifier('entity', 'id');
     $metadataFactory = $this->getMock('Pok\\PoolDBM\\Mapping\\ClassMetadataFactory', array('getMetadataFor', 'setModelManager'));
     $metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
     $pool = new Pool();
     $pool->addManager('entity', new EntityManager());
     $manager = new ModelManager($pool, $metadataFactory);
     $this->assertInstanceOf('Pok\\PoolDBM\\Mapping\\ClassMetadataFactory', $manager->getMetadataFactory());
     $this->assertTrue($manager->getPool()->hasManager('entity'));
     $this->assertInstanceOf(get_class($metadata), $manager->getClassMetadata(__NAMESPACE__ . '\\ModelTest'));
     $this->assertTrue($manager->createQueryBuilder(__NAMESPACE__ . '\\ModelTest', 'test'));
     $this->assertInstanceOf('Pok\\PoolDBM\\ModelRepository', $manager->getRepository(__NAMESPACE__ . '\\ModelTest'));
     $this->assertTrue($manager->contains(new ModelTest()));
     // unitOfWork
     $this->assertInstanceOf('Pok\\PoolDBM\\UnitOfWork', $manager->getUnitOfWork());
     $manager->persist(new ModelTest());
     $manager->remove(new ModelTest());
     $manager->refresh(new ModelTest());
     $manager->detach(new ModelTest());
     $manager->merge(new ModelTest());
     $manager->flush(new ModelTest());
     $manager->close();
     try {
         $manager->flush(new ModelTest());
     } catch (\RuntimeException $e) {
         $this->assertEquals('Model manager is closed.', $e->getMessage());
     }
 }
예제 #3
0
 protected function createModelManager($metadataDriver)
 {
     $pool = new Pool();
     $pool->addManager('entity', new ObjectManagerMock());
     $pool->addManager('document', new ObjectManagerMock());
     $manager = new ModelManager($pool);
     $manager->setMetadataDriverImpl($metadataDriver);
     return $manager;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getPriority($name)
 {
     if (!$this->hasPriority($name)) {
         throw new \RuntimeException(sprintf('The priority managers name "%s" does not exists.', $name));
     }
     return parent::getPriority($name);
 }
 public function testExecute()
 {
     $metadata = new \Pok\PoolDBM\Mapping\ClassMetadata(__NAMESPACE__ . '\\ModelTest');
     $metadata->addModel('entity', __NAMESPACE__ . '\\EntityTest', array());
     $metadata->setIdentifier('entity', 'id');
     $metadataFactory = $this->getMock('Pok\\PoolDBM\\Mapping\\ClassMetadataFactory', array('getMetadataFor', 'setModelManager'));
     $metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
     $pool = new Pool();
     $pool->addManager('entity', new ObjectManagerMock());
     $manager = new ModelManager($pool, $metadataFactory);
     $manager->setMetadataDriverImpl(new MetadataDriverMock(array(__NAMESPACE__ . '\\ModelTest')));
     $application = new Application();
     $application->setHelperSet(new HelperSet(ConsoleRunner::createHelpers($manager)));
     $application->add(new GenerateMultiModelCommand());
     $command = $application->find('pok:pool-dbm:generate:model');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'dest-path' => sys_get_temp_dir(), '--auto-update' => true));
 }
예제 #6
0
 public function test2()
 {
     $metadatas = array();
     $metadata = new ClassMetadata($this->getFixtures('Test2\\Model\\User'));
     $metadata->addModel('entity', $this->getFixtures('Test2\\Entity\\User'), array(), 'findByIds');
     $metadata->addModel('document', $this->getFixtures('Test2\\Document\\User'), array(), 'findByIds');
     $metadata->setIdentifier('entity', 'id');
     $metadata->addAssociation(true, 'groups', $this->getFixtures('Test2\\Model\\Group'));
     $metadatas[$this->getFixtures('Test2\\Model\\User')] = $metadata;
     $metadata = new ClassMetadata($this->getFixtures('Test2\\Model\\Group'));
     $metadata->addModel('entity', $this->getFixtures('Test2\\Entity\\Group'), array(), 'findByIds');
     $metadata->addModel('document', $this->getFixtures('Test2\\Document\\Group'), array(), 'findByIds');
     $metadata->setIdentifier('entity', 'id');
     $metadata->addIdentifierReference('document', 'documentId', 'id');
     $metadata->addAssociation(true, 'users', $this->getFixtures('Test2\\Model\\User'));
     $metadatas[$this->getFixtures('Test2\\Model\\Group')] = $metadata;
     $metadataFactory = $this->getMock('Pok\\PoolDBM\\Mapping\\ClassMetadataFactory', array('getMetadataFor', 'setModelManager'));
     $metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnCallback(function ($className) use($metadatas) {
         if (!isset($metadatas[$className])) {
             throw new \RuntimeException(sprintf('Class "%s" not register.', $className));
         }
         return $metadatas[$className];
     }));
     $pool = new Pool();
     $pool->addManager('entity', new Fixtures\Test2\EntityManager());
     $pool->addManager('document', new Fixtures\Test2\DocumentManager());
     $manager = new ModelManager($pool, $metadataFactory);
     // User
     $persisters = new ModelPersister($manager, new UnitOfWork($manager), $metadatas[$this->getFixtures('Test2\\Model\\User')]);
     $this->assertInstanceOf('Pok\\PoolDBM\\Mapping\\ClassMetadata', $persisters->getClassMetadata());
     // load 1
     $model = $persisters->load(1);
     $this->assertInstanceOf($this->getFixtures('Test2\\Model\\User'), $model);
     $this->assertInstanceOf($this->getFixtures('Test2\\Entity\\User'), $model->entity);
     $this->assertEquals(1, $model->entity->id);
     $this->assertInstanceOf($this->getFixtures('Test2\\Document\\User'), $model->document);
     $this->assertEquals($model->entity->id, $model->document->id);
     $this->assertEquals(0, count($model->groups));
     // force optimization
     // Group
     $persisters = new ModelPersister($manager, new UnitOfWork($manager), $metadatas[$this->getFixtures('Test2\\Model\\Group')]);
     $this->assertInstanceOf('Pok\\PoolDBM\\Mapping\\ClassMetadata', $persisters->getClassMetadata());
     // load 1
     $model = $persisters->load(1);
     $this->assertInstanceOf($this->getFixtures('Test2\\Model\\Group'), $model);
     $this->assertInstanceOf($this->getFixtures('Test2\\Entity\\Group'), $model->entity);
     $this->assertEquals(1, $model->entity->id);
     $this->assertInstanceOf($this->getFixtures('Test2\\Document\\Group'), $model->document);
     $this->assertEquals($model->entity->documentId, $model->document->id);
     $this->assertEquals(0, count($model->users));
     // force optimization
 }