Exemple #1
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());
     }
 }
 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));
 }