/** * Add Record to collection * * @param \Migration\ResourceModel\Record $record * @return $this * @throws Exception */ public function addRecord($record) { if (!$record->getStructure()) { $record->setStructure($this->structure); } if (!$record->validateStructure($this->structure)) { throw new Exception("Record structure does not equal Collection structure"); } $this->data[] = $record; return $this; }
/** * {@inheritdoc} */ public function validate(Record $record) { $offsetInt = $this->offset; $sign = substr($this->offset, 0, 1); if (in_array($sign, [self::SIGN_PLUS, self::SIGN_MINUS])) { $offsetInt = substr($this->offset, 1, strlen($this->offset) - 1); } else { $sign = self::SIGN_PLUS; } if (self::SIGN_PLUS === $sign && $offsetInt > self::MAX_OFFSET || self::SIGN_MINUS === $sign && $offsetInt < self::MIN_OFFSET) { throw new Exception('Offset can have value between ' . '"' . self::MIN_OFFSET . '" and "' . self::SIGN_PLUS . self::MAX_OFFSET . '""'); } $fieldType = $record->getStructure()->getFields()[$this->field]['DATA_TYPE']; if (!in_array($fieldType, $this->supportedDatatypes)) { throw new Exception('Provided datatype for field "' . $this->field . '" is not supported'); } parent::validate($record); }
/** * @covers \Migration\ResourceModel\Record::getStructure * @covers \Migration\ResourceModel\Record::setStructure * @return void */ public function testGetStructure() { $this->record->setStructure($this->structure); $this->assertSame($this->structure, $this->record->getStructure()); }