/**
  * @BeforeScenario
  */
 public function purgeDatabase()
 {
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $purger = new ORMPurger($this->entityManager);
     $purger->purge();
     $this->entityManager->clear();
 }
 /**
  * {@inheritdoc}
  */
 public function startJobs(ProjectInterface $project)
 {
     $query = 'UPDATE Worldia\\Bundle\\TextmasterBundle\\Entity\\Job j ' . 'SET j.status = :status ' . 'WHERE j.projectId = :projectId ';
     $q = $this->entityManager->createQuery($query)->setParameter('status', JobInterface::STATUS_STARTED)->setParameter('projectId', $project->getId());
     $q->execute();
     $this->entityManager->clear();
 }
 /**
  * @BeforeScenario
  */
 public function purgeDatabase()
 {
     if (null === $this->entityManager) {
         throw new \RuntimeException('Cannot purge database. Entity manager is not set');
     }
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $purger = new ORMPurger($this->entityManager);
     $purger->purge();
     $this->entityManager->clear();
 }
 /**
  * @return EntityManagerInterface
  * @throws \PHPUnit_Framework_SkippedTestError
  * @throws \InvalidArgumentException
  * @throws \Doctrine\ORM\ORMException
  */
 public static function getEntityManager()
 {
     if (null === self::$entityManager) {
         if (!extension_loaded('ibm_db2')) {
             throw new \PHPUnit_Framework_SkippedTestError('DB2 connection is unavailable, skipping test');
         }
         $configuration = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/entity/'], true);
         if (!file_exists(__DIR__ . '/config/local.php')) {
             throw new \PHPUnit_Framework_SkippedTestError('test/config/local.php not found');
         }
         $connection = (require __DIR__ . '/config/local.php');
         self::$entityManager = EntityManager::create($connection, $configuration);
     }
     self::$entityManager->clear();
     return self::$entityManager;
 }
 /**
  * @param $ticketDetail
  */
 private function removeVisitor()
 {
     self::$entityManager->clear();
     $ticketDetail = self::$entityManager->getRepository('AppBundle:TicketDetail')->find(self::$ticketDetailId);
     $visitor = $ticketDetail->getVisitor();
     $ticketDetail->setVisitor();
     self::$entityManager->remove($visitor);
     self::$entityManager->flush();
 }
 /**
  * @param array  $selectedIds
  * @param string $value
  *
  * @return int
  */
 protected function finishBatch(array &$selectedIds, $value)
 {
     $qBuilder = $this->entityManager->createQueryBuilder();
     $entitiesCount = $qBuilder->update($this->entityName, 'e')->set('e.' . $this->fieldName, ':value')->where($qBuilder->expr()->in('e.' . $this->identifierName, $selectedIds))->getQuery()->setParameter('value', $value)->execute();
     $this->entityManager->flush();
     if ($this->entityManager->getConnection()->getTransactionNestingLevel() == 1) {
         $this->entityManager->clear();
     }
     $selectedIds = [];
     return $entitiesCount;
 }
 /**
  * @Given /^order "([^"]*)" has the following products:$/
  *
  * @param $orderNumber
  * @param TableNode $table
  */
 public function orderHasTheFollowingProducts($orderNumber, TableNode $table)
 {
     /** @var OrderInterface $order */
     $order = $this->orderRepository->findOneBy(['number' => $orderNumber]);
     foreach ($table->getHash() as $row) {
         $product = $this->productRepository->findOneByName($row['name']);
         /** @var OrderItemInterface $orderItem */
         $orderItem = $this->orderItemFactory->createNew();
         $orderItem->setVariant($product->getFirstVariant());
         $order->addItem($orderItem);
     }
     $this->entityManager->flush();
     $this->entityManager->clear();
 }
 public function clear()
 {
     $this->em->clear();
 }
 /**
  *
  */
 public function clear()
 {
     $this->entityManager->clear();
 }
 protected function clean()
 {
     $em = $this->em;
     $reflectedEm = new \ReflectionClass($em);
     if ($reflectedEm->hasProperty('repositories')) {
         $property = $reflectedEm->getProperty('repositories');
         $property->setAccessible(true);
         $property->setValue($em, []);
     }
     $this->em->clear();
 }
 /**
  * Flush and clear the entity manager
  */
 public function flush()
 {
     $this->entityManager->flush();
     $this->entityManager->clear($this->entityName);
 }
 public function clear()
 {
     $this->entityManager->clear();
     $this->fingersCrossedHandler->clear();
 }
 private function findAllEntity(EntityManagerInterface $em, $label)
 {
     $times = 100;
     $size = 50;
     $startPersist = microtime(true);
     $rep = $em->getRepository(Country::CLASSNAME);
     echo PHP_EOL . $label;
     for ($i = 0; $i < $size; $i++) {
         $em->persist(new Country("Country {$i}"));
     }
     $em->flush();
     $em->clear();
     printf("\n[%s] persist %s countries", number_format(microtime(true) - $startPersist, 6), $size);
     $startFind = microtime(true);
     for ($i = 0; $i <= $times; $i++) {
         $list = $rep->findAll();
         $em->clear();
         $this->assertCount($size, $list);
     }
     printf("\n[%s] find %s countries (%s times)", number_format(microtime(true) - $startFind, 6), $size, $times);
     printf("\n%s\n", str_repeat('-', 50));
 }
 /**
  * We need to clear identity map before navigating to next record.
  */
 public function next()
 {
     $this->manager->clear();
     parent::next();
 }
 /**
  * @return void
  */
 private function flushAndClearEntityManager()
 {
     $this->entityManager->flush();
     $this->entityManager->clear();
 }