/** * Validates response from server from National Bank of Serbia. * * <b>NOTE TO READER:</b> This is not proper test against returned response. Proper test would check response against * XMLSchema, however, IT department of National Bank of Serbia apparently does not think that it is convenient to deliver * XMLSchema with XML document. I wonder if they have it at all... * * @param string $rateType */ protected function assertXmlDocumentIsValid($rateType) { $browser = new NbsBrowser(); $xmlContent = $browser->getXmlDocument(new \DateTime('now'), $rateType)->getContents(); $parser = new XmlParser(); $stream = fopen('php://memory', 'r+'); fwrite($stream, $xmlContent); rewind($stream); $parser->parse(new Stream($stream), \Closure::bind(function ($rates) { $this->assertTrue(count($rates) > 0); }, $this)); switch ($rateType) { case 'default': $this->assertContains('OFFICIAL MIDDLE EXCHANGE RATE OF THE DINAR', $xmlContent, 'Should be XML with median exchange rates.'); break; case 'foreign_cash_buying': $this->assertContains('FOREIGN CASH', $xmlContent, 'Should be XML with foreign cash rates.'); break; case 'foreign_exchange_buying': $this->assertContains('FOREIGN EXCHANGE', $xmlContent, 'Should be XML with foreign exchange rates.'); break; } }
/** * Load rates from National Bank of Serbia website. * * @param \DateTime $date * @param string $rateType * @return RateInterface[] * @throws SourceNotAvailableException */ private function load(\DateTime $date, $rateType) { $parser = new XmlParser(); $parser->parse($this->browser->getXmlDocument($date, $rateType), \Closure::bind(function ($rates) { /** * @var RateInterface $rate */ foreach ($rates as $rate) { if (!array_key_exists($rate->getRateType(), $this->cache)) { $this->cache[$rate->getRateType()] = array(); } $this->cache[$rate->getRateType()][$rate->getCurrencyCode()] = $rate; } }, $this)); }