/** * @return SegmentPrinter */ protected function givenPrinter() { $segmentMapping = new SegmentMapping('XXX'); $segmentMapping->addDataElement(1, new DataElementMapping(5434, true, DataElementType::ID, 'ajdi')); $segmentMapping->addDataElement(2, new DataElementMapping(4525, true, DataElementType::A, 'fild')); $compDataElement = new CompositeDataElementMapping(2435, true, DataElementType::COMPOSITE, 'araj'); $compDataElement->addDataElement(new DataElementMapping(6456, true, DataElementType::A, 'e1')); $compDataElement->addDataElement(new DataElementMapping(3567, true, DataElementType::A, 'e2')); $segmentMapping->addDataElement(3, $compDataElement); $segmentYMapping = new SegmentMapping('YYY'); $segmentYMapping->addDataElement(1, new DataElementMapping(5434, true, DataElementType::ID, 'ajdi')); $printer = new SegmentPrinter(); $printer->setSegmentMappings(['XXX' => $segmentMapping, 'YYY' => $segmentYMapping]); return $printer; }
/** @test */ public function should_populate_according_to_config() { $segmentMapping = new SegmentMapping('XXX'); $segmentMapping->addDataElement(1, new DataElementMapping(7583, true, DataElementType::ID, 'ajdi', '', 3)); $segmentMapping->addDataElement(2, new DataElementMapping(3415, false, DataElementType::A, 'field', '', 35)); $compDataElement = new CompositeDataElementMapping(7583, false, DataElementType::COMPOSITE, 'comp'); $compDataElement->addDataElement(new DataElementMapping(1111, false, DataElementType::A, 'ajnc')); $compDataElement->addDataElement(new DataElementMapping(2222, false, DataElementType::A, 'cfaj')); $segmentMapping->addDataElement(3, $compDataElement); $populator = new SegmentPopulator(); $populator->setSegmentConfig(['XXX' => $segmentMapping]); $data = [['XXX', '345', 'some data', ['whatever', 'content']]]; $segment = $populator->populate($data); $this->assertEquals(345, $segment->ajdi); $this->assertEquals('some data', $segment->field); $this->assertEquals('whatever', $segment->comp['ajnc']); $this->assertEquals('content', $segment->comp['cfaj']); }