/** * @param $xmlFilePath * @return \Generator|Product[] */ public function readFromPath($xmlFilePath) { $xml = new \XMLReader(); $xml->open($xmlFilePath); while ($xml->read() && $xml->name !== 'product') { } $decoder = new XmlDecoder(); while ($xmlData = $xml->readOuterXml()) { (yield $decoder->decodeProduct(new \SimpleXMLElement($xmlData))); $xml->next('product'); } $xml->close(); }
function testAttribute() { $decoder = new XmlDecoder(); $attributeValue = $decoder->decodeAttribute($this->getXml()->attribute[0]); $this->assertEquals('b9i9ssr4lxk4', $attributeValue->getAttribute()->getUid()); $this->assertEquals('Barva', $attributeValue->getAttribute()->getName()); $this->assertEquals(['bílá', 'modrá', 'ocelová'], $attributeValue->getValues()); }