public function testWriteData() { $cell = new Cell(); $cell->setExportValue('Export'); $row = new Row(); $row->addCell($cell); $rows = new ArrayCollection(); $rows->add($row); $export = new ExcelExport($this->factory); $export->setPhpExcel(new PHPExcel()); $export->writeData($rows); $exportObject = $export->getPhpExcel(); $this->assertEquals('Export', $exportObject->getActiveSheet()->getCell('A2')->getValue()); }
public function testMapRows() { $column = new Column(); $column->setProperty('name'); $column->setCellType(new TextCell()); $column->setLabel('User name'); $columnCollection = new ArrayCollection(); $columnCollection->add($column); $user = new User(); $user->setId(1); $user->setName('some random name'); $user->setEmail('*****@*****.**'); $rowCollection = new ArrayCollection(); $rowCollection->add($user); $mapper = new DatagridMapper(); $actual = $mapper->mapRows($rowCollection, $columnCollection); $cell = new Cell(); $cell->setProperty('name'); $cell->setValue('some random name'); $cell->setExportValue('some random name'); $cell->setType('text'); $cell->setView('text'); $cell->setAttributes([]); $row = new Row(); $row->setId(1); $row->setName(1); $row->setObject($user); $row->addCell($cell); $expected = new ArrayCollection(); $expected->add($row); $this->assertEquals($actual, $expected); }
/** * Map a single row * * @param object $object The object the row represents * @param array $columns The columns that should be added to the row * * @return Row */ public function mapRow($object, $columns) { $row = new Row(); $row->setObject($object); $row->setId($object->getId()); $row->setName($object->getId()); foreach ($columns as $column) { $cellFactory = new CellFactory(); $cell = $cellFactory->create($column, $object); $row->addCell($cell); } return $row; }