public function testCountErrorsWithDebugHandler() { $handler = new DebugHandler(); $logger = new Logger(__METHOD__, array($handler)); $this->assertTrue($logger->debug('test message')); $this->assertTrue($logger->info('test message')); $this->assertTrue($logger->notice('test message')); $this->assertTrue($logger->warning('test message')); $this->assertTrue($logger->error('test message')); $this->assertTrue($logger->critical('test message')); $this->assertTrue($logger->alert('test message')); $this->assertTrue($logger->emergency('test message')); $this->assertSame(4, $logger->countErrors()); }
/** * @internal */ public function saveExchangeRates($force = false, array $currencyRates = array()) { $this->logger->info(sprintf('[|%s] Rates sync is started.', Utils::getClassBasename($this))); if (!empty($currencyRates)) { $this->currencyRates = $currencyRates; } if (!empty($this->currencyRates)) { try { // Iterate the currencies foreach ($this->currencyRates as $currencyCode => $dates) { $lastDateObj = new \DateTime(key($dates)); $lastRateValue = current($dates); // Iterate the date and rate foreach ($dates as $date => $value) { $dateObj = new \DateTime($date); // Persist rates for date differences between current and last date (weekend) $interval = date_diff($lastDateObj, $dateObj); $this->setMissingRatesAndPersist($lastDateObj, $interval->format('%d') - 1, $currencyCode, $lastRateValue, $force); // Persist the current rate $rate = $this->createOrUpdateRate($currencyCode, $value, $dateObj, $force); if (null !== $rate) { $this->em->persist($rate); } $lastDateObj = clone $dateObj; $lastRateValue = $value; } // Insert difference of last MNB date and tomorrow using last MNB rate $tomorrow = new \DateTime('tomorrow'); $difference = $tomorrow->diff($lastDateObj); $this->setMissingRatesAndPersist($lastDateObj, $difference->format('%d'), $currencyCode, $value, $force); } $this->em->flush(); $this->logger->info(sprintf('[|%s] Rates synced successfully.', Utils::getClassBasename($this))); } catch (Exception $exc) { $this->logger->error(sprintf('[|%s] Rates synced FAILED! Error message: ' . $exc->getTraceAsString(), Utils::getClassBasename($this))); } return true; } else { $this->logger->alert(sprintf('[|%s] The currency rates array is empty.', Utils::getClassBasename($this))); return false; } $this->logger->info(sprintf('[|%s] Rates sync is ended.', Utils::getClassBasename($this))); }