public function testRead() { $reader = new CachedReader(); $data = array('row1' => array('key1' => 'value1', 'key2' => 'value2'), 'row2' => array('key1' => 'value3', 'key2' => 'value4')); foreach ($data as $key => $value) { $reader->addItem($value, $key); } $data['row2']['extra'] = 'value5'; $reader->addItem($data['row2'], 'row2'); $this->assertEquals($data['row2'], $reader->getItem('row2')); $newElement = array('key1' => 'value6'); $data[] = $newElement; $reader->addItem($newElement); foreach ($data as $row) { $this->assertEquals($row, $reader->read()); } $this->assertNull($reader->read()); }
/** * Sets the product's associations * * @param type $entity * @param array $data */ protected function setAssociations($entity, array $data) { if (!count($this->assocColumnsInfo)) { return; } $associations = []; foreach ($this->assocColumnsInfo as $columnInfo) { $label = $columnInfo->getLabel(); if (!array_key_exists($label, $data) || empty($data[$label])) { continue; } $key = $entity->getReference() . '.' . $columnInfo->getName(); $suffixes = $columnInfo->getSuffixes(); $lastSuffix = array_pop($suffixes); if (!isset($associations[$key])) { $associations[$key] = ['association_type' => $columnInfo->getName(), 'owner' => $entity->getReference()]; } $associations[$key][$lastSuffix] = $data[$label]; } foreach ($associations as $association) { $this->associationReader->addItem($association); } }