Пример #1
0
 public function setUp()
 {
     // Boot the AppKernel in the test environment and with the debug.
     $this->kernel = new \AppKernel('test', true);
     $this->kernel->boot();
     // Store the container and the entity manager in test case properties
     $this->container = $this->kernel->getContainer();
     $this->entityManager = $this->container->get('doctrine')->getManager();
     $this->entityManager->clear();
     // Build the schema for sqlite
     $this->generateSchema();
     parent::setUp();
 }
Пример #2
0
 public function getConnection()
 {
     // Retrieve PDO instance
     $pdo = $this->em->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $this->em->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $classes = $this->em->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     // Pass to PHPUnit
     return $this->createDefaultDBConnection($pdo, 'db_name');
 }
 public function flush($remoteOperations = null, $fetchMode = null)
 {
     // If $remoteOperations is null, flush() has been called from a server-side method so we don't want to clear the em
     if ($remoteOperations) {
         $this->em->clear();
     }
     // Start the transaction
     $this->em->getConnection()->beginTransaction();
     try {
         // Perform the flush
         $flushExecutor = new FlushExecutor($this->em, $remoteOperations, $this->deserializationWalker);
         $changeSets = $flushExecutor->flush();
         // Go through the elements in the change sets making the entities Flextrine ready (apart from temporaryUidMap and entityDeletionIdMap which are not entities)
         if ($fetchMode) {
             $this->setFetchMode($fetchMode);
         }
         foreach ($changeSets as $changeSetType => $changeSet) {
             if ($changeSetType != "temporaryUidMap" && $changeSetType != "entityDeletionIdMap") {
                 foreach ($changeSet as $oid => $entity) {
                     $changeSet[$oid] = $this->flextrinize($entity);
                 }
             }
         }
         // Commit the transaction
         $this->em->getConnection()->commit();
         // Return the change sets so they can be replicated in Flextrine
         return $changeSets;
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         $this->em->close();
         throw $e;
     }
 }
Пример #4
0
 /**
  * Set default article image
  *
  * @param int            $articleNumber
  * @param ImageInterface $image
  *
  * @return void
  */
 public function setDefaultArticleImage($articleNumber, ArticleImage $image)
 {
     $query = $this->orm->createQuery('UPDATE Newscoop\\Image\\ArticleImage i SET i.isDefault = 0 WHERE i.articleNumber = :articleNumber');
     $query->setParameter('articleNumber', $articleNumber)->execute();
     $image->setIsDefault(true);
     $this->orm->flush($image);
     $this->orm->clear();
 }
Пример #5
0
 /**
  * @param mixed $classes
  * @return void
  */
 public function setUp()
 {
     $this->doctrine = Zend_Registry::get('container')->getService('doctrine');
     $this->em = $this->doctrine->getEntityManager();
     $this->em->clear();
     $tool = new SchemaTool($this->em);
     $tool->dropDatabase();
     $classes = func_get_args();
     if (!empty($classes)) {
         $metadataFactory = new ClassMetadataFactory();
         $metadataFactory->setEntityManager($this->em);
         $metadataFactory->setCacheDriver(new ArrayCache());
         $metadata = array();
         foreach ((array) $classes as $class) {
             $metadata[] = $metadataFactory->getMetadataFor($class);
         }
         $tool->createSchema($metadata);
     }
 }
Пример #6
0
 public function testDelete()
 {
     $package = $this->service->save(array('headline' => 'tic'));
     $this->service->addItem($package, new LocalImage(self::PICTURE_LANDSCAPE));
     $this->service->saveArticle(array('id' => 1, 'slideshows' => array(array('id' => $package->getId()))));
     $this->service->delete($package->getId());
     $this->orm->clear();
     $this->assertEquals(0, count($this->service->findBy(array())));
     $this->assertEquals(0, count($this->orm->getRepository('Newscoop\\Package\\Item')->findAll()));
     $this->assertEquals(0, count($this->service->findByArticle(1)));
 }
Пример #7
0
 public function testLiftEmbargoOld()
 {
     $feed = new Feed('SDA');
     $this->service->addFeed($feed);
     $entry = $this->getEntry(array('getTitle' => 'test', 'getContent' => 'test', 'getStatus' => 'Embargoed', 'getLiftEmbargo' => new \DateTime('-2 day')));
     $this->em->persist($entry);
     $this->em->flush();
     $this->em->clear();
     $this->service->updateSDA();
     $loaded = $this->em->find('Newscoop\\Entity\\Ingest\\Feed\\Entry', $entry->getId());
     $this->assertEquals('Usable', $loaded->getStatus());
 }
Пример #8
0
 /**
  * Set up DB for use with Doctrine tests
  *
  * @return void
  */
 public function setUp()
 {
     // Truncate all tables
     $tables = array();
     #$metadata = self::$entityManager->getMetadataFactory()->getAllMetadata();
     foreach (self::$metadata as $metadatum) {
         $tables[] = $metadatum->getTableName();
     }
     foreach ($tables as $table) {
         #self::$entityManager->createNativeQuery('DELETE FROM ' . $table, new ResultSetMapping())->getResult();
         self::$entityManager->getConnection()->executeUpdate('DELETE FROM ' . $table);
         #self::$entityManager->createNativeQuery('UPDATE sqlite_sequence SET seq=0 WHERE name="'.$table.'"', new ResultSetMapping())->getResult();
         #self::$entityManager->createNativeQuery('DELETE FROM sqlite_sequence WHERE name=\''.$table.'\'', new ResultSetMapping())->getResult();
     }
     self::$entityManager->clear();
 }
 /**
  * Create a new message.
  *
  * @param ZendQueue\Queue $queue
  * @param string          $body
  */
 protected function createMessage(Queue $queue, $body)
 {
     // check if message exist
     $message = $this->em->getRepository('Heri\\Bundle\\JobQueueBundle\\Entity\\Message')->findOneBy(['md5' => md5($body)]);
     if (!$message) {
         $message = new \Heri\Bundle\JobQueueBundle\Entity\Message();
         $message->setQueue($this->getQueueEntity($queue->getName()));
         $message->setBody($body);
         $message->setMd5(md5($body));
         $message->setPriority($this->priority);
         $message->setFailed(false);
         $message->setEnded(false);
         $this->em->persist($message);
         $this->em->flush();
         $this->em->clear();
     }
     return $message;
 }
Пример #10
0
 /**
  * createModuleData.
  */
 public function createModuleData()
 {
     $aFields = $this->getFields();
     $aContent = array();
     foreach ($aFields as $field) {
         $aContent[$field['identifier']] = $field['testData'];
     }
     $oModule = new Module();
     $oModule->setName('Test Module');
     $oModule->setDescription('test');
     $sequence = 0;
     foreach ($aFields as $field) {
         $oField = new Field();
         $oField->setName($field['name']);
         $oField->setFormType($field['form']);
         $oField->setIdentifier($field['identifier']);
         $this->em->persist($oField);
         $oModuleHasField = new ModuleHasField();
         $oModuleHasField->setField($oField);
         $oModuleHasField->setModule($oModule);
         $oModuleHasField->setSequence($sequence);
         $this->em->persist($oModuleHasField);
         ++$sequence;
     }
     $this->em->flush();
     for ($i = 0; $i < $this->rows; ++$i) {
         $container = new Container();
         $container->setModule($oModule);
         $container->setSequence(999);
         $this->em->persist($container);
         $this->em->flush();
         $this->container->enterScope('request');
         $this->container->set('request', new Request(), 'request');
         $object = $this->container->get('eav.module.manager');
         $object->setModule($oModule);
         $object->save($container, $aContent);
     }
     $this->em->clear();
 }